PyTorch torch.vander Function
Pytorch torch Reference Manual
torch.vanderIt is a function in PyTorch used to generate a Vandermonde matrix. A Vandermonde matrix is a special matrix where each row consists of the powers of the input vector.
Function Definition
torch.vander(x, N=None, increasing=False)
Parameters:
x(Tensor): 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 input vector
x = torch.tensor([1, 2, 3])
# Generate Vandermonde matrix
V = torch.vander(x)
print("Input vector x:", x)
print("nVandermonde matrix:")
print(V)
# Create input vector
x = torch.tensor([1, 2, 3])
# Generate Vandermonde matrix
V = torch.vander(x)
print("Input vector x:", x)
print("nVandermonde matrix:")
print(V)
The output result is:
输入向量 x: tensor([1, 2, 3])
Vandermonde 矩阵:
tensor([[1, 1, 1],
[4, 2, 1],
[9, 3, 1]])
Example - Increasing Powers
import torch
x = torch.tensor([1, 2, 3])
# Generate the Vandermonde matrix with increasing powers
V_inc = torch.vander(x, increasing=True)
print("Increasing Vandermonde matrix:")
print(V_inc)
Example - Specifying the Number of Columns
import torch
x = torch.tensor([1, 2, 3, 4])
# Generate a Vandermonde matrix with 5 columns
V = torch.vander(x, N=5)
print("Input vector x:", x)
print("nVandermonde matrix (5 columns):")
print(V)