PyTorch torch.vander function
PyTorch torch reference manual
torch.vander is a function in PyTorch used to generate a Vandermonde matrix. A Vandermonde matrix is a special matrix in which each row is a power of the input vector.
Function definition
torch.vander(x, N=None, increasing=False)
Parameters:
x(Tensor): The input one-dimensional tensor.N(int, optional): The number of columns in the output matrix. Defaults to len(x).increasing(bool, optional): If True, the powers of the columns increase; otherwise, they decrease. Defaults to False.
Return Value:
torch.Tensor: Returns the Vandermonde matrix.
Usage examples
Example
import
torch
Create the input vector
x
=
torch.
tensor
(
[
1
,
2
,
3
]
)
Generate the Vandermonde matrix
V
=
torch.
vander
(
x
)
(
"Input vector x:"
,
x
)
(
"nVandermonde matrix:"
)
(
V
)
The output is:
输入向量 x: tensor([1, 2, 3])
Vandermonde 矩阵:
tensor([[1, 1, 1],
[4, 2, 1],
[9, 3, 1]])
实例 - 递增幂次
import torch
x = torch.tensor([1, 2, 3])
# Generate Vandermonde matrix with increasing powers
V_inc = torch.vander(x, increasing=True)
print("递增 Vandermonde 矩阵:")
print(V_inc)
实例 - 指定列数
import torch
x = torch.tensor([1, 2, 3, 4])
# Generate a 5-column Vandermonde matrix
V = torch.vander(x, N=5)
print("输入向量 x:", x)
print("nVandermonde 矩阵 (5列):")
print(V)
Pytorch torch 参考手册