Pytorch Torch Vander
# PyTorch torch.vander Function
* * *
[ Pytorch torch Reference Manual](https://example.com/pytorch/pytorch-torch-ref.html)
`torch.vander` is a function in PyTorch used to generate a Vandermonde matrix. A Vandermonde matrix is a special matrix where each row is a power of the input vector.
### Function Definition
torch.vander(x, N=None, increasing=False)
**Parameters**:
* `x` (Tensor): Input one-dimensional tensor.
* `N` (int, optional): Number of columns in the output matrix. Default is len(x).
* `increasing` (bool, optional): If True, the powers of columns increase; otherwise, they decrease. Default is False.
**Return Value**:
* `torch.Tensor`: Returns a 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)
The output is:
Input vector x: tensor([1, 2, 3])Vandermonde Matrix: tensor([[1, 1, 1], [4, 2, 1], [9, 3, 1]])
## Example - Increasing Powers
import torch
x = torch.tensor([1, 2, 3])
# Generate Vandermonde matrix with increasing powers
V_inc = torch.vander(x, increasing=True)
print("Increasing Vandermonde Matrix:")
print(V_inc)
## Example - Specify Number of Columns
import torch
x = torch.tensor([1, 2, 3, 4])
# Generate Vandermonde matrix with 5 columns
V = torch.vander(x, N=5)
print("Input vector x:", x)
print("nVandermonde Matrix (5column):")
print(V)
* * *
[ Pytorch torch Reference Manual](https://example.com/pytorch/pytorch-torch-ref.html)
YouTip