評價此頁

torch.linalg.vander#

torch.linalg.vander(x, N=None) Tensor#

生成 Vandermonde 矩陣。

返回 Vandermonde 矩陣 VV

V=(1x1x12x1N11x2x22x2N11x3x32x3N11xnxn2xnN1).V = \begin{pmatrix} 1 & x_1 & x_1^2 & \dots & x_1^{N-1}\\ 1 & x_2 & x_2^2 & \dots & x_2^{N-1}\\ 1 & x_3 & x_3^2 & \dots & x_3^{N-1}\\ \vdots & \vdots & \vdots & \ddots &\vdots \\ 1 & x_n & x_n^2 & \dots & x_n^{N-1} \end{pmatrix}.

對於 N > 1。如果 N= None,則 N = x.size(-1),以便輸出為方陣。

支援浮點、雙精度、複數浮點、複數雙精度和整數資料型別的輸入。也支援向量批次,如果 x 是向量批次,則輸出具有相同的批次維度。

numpy.vander 的區別

  • numpy.vander 不同,此函式返回 x 的冪次按升序排列。要以相反的順序獲取,請呼叫 linalg.vander(x, N).flip(-1)

引數

x (Tensor) – 形狀為 (*, n) 的張量,其中 * 是零個或多個批次維度,由向量組成。

關鍵字引數

N (int, optional) – 輸出中的列數。預設值:x.size(-1)

示例

>>> x = torch.tensor([1, 2, 3, 5])
>>> linalg.vander(x)
tensor([[  1,   1,   1,   1],
        [  1,   2,   4,   8],
        [  1,   3,   9,  27],
        [  1,   5,  25, 125]])
>>> linalg.vander(x, N=3)
tensor([[ 1,  1,  1],
        [ 1,  2,  4],
        [ 1,  3,  9],
        [ 1,  5, 25]])