Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.vander function

PyTorch torch.vander function


PyTorch torch reference manual 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:

Return Value:


Usage examples

Example

import

torch

Create the input vector

x

=

torch.

tensor

(

[

1

,

2

,

3

]

)

Generate the Vandermonde matrix

V

=

torch.

vander

(

x

)

print

(

"Input vector x:"

,

x

)

print

(

"nVandermonde matrix:"

)

print

(

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 参考手册