Python numpy.vander()函数
numpy.vander()函数被用来生成一个范德蒙德矩阵。
语法 : numpy.vander(arr, N = None, increasing = False)
参数 :
arr : [ array_like] 1-D输入阵列。
N : [int, optional] 输出中的列的数量。如果没有指定N,将返回一个方形数组(N = len(x))。
increasing : [bool, optional] 列的幂的顺序。如果为真,幂数从左到右增加,如果为假(默认),则相反。
返回: [ndarray] dVandermonde矩阵。如果递增为假,第一列是x^(N-1),第二列是x^(N-2),以此类推。如果递增为True,列是x^0, x^1, …, x^(N-1)。
代码#1:
# Python program explaining
# numpy.vander() function
# importing numpy as geek
import numpy as geek
arr = geek.array([1, 2, 3, 4, 5])
gfg = geek.vander(arr)
print (gfg)
输出 :
[[ 1 1 1 1 1]
[ 16 8 4 2 1]
[ 81 27 9 3 1]
[256 64 16 4 1]
[625 125 25 5 1]]
代码#2:
# Python program explaining
# numpy.vander() function
# importing numpy as geek
import numpy as geek
arr = geek.array([1, 2, 3, 4, 5])
N = 3
gfg = geek.vander(arr, N)
print (gfg)
输出 :
[[ 1 1 1]
[ 4 2 1]
[ 9 3 1]
[16 4 1]
[25 5 1]]
代码#3:
# Python program explaining
# numpy.vander() function
# importing numpy as geek
import numpy as geek
arr = geek.array([1, 2, 3, 4, 5])
gfg = geek.vander(arr, increasing = True)
print (gfg)
输出 :
[[ 1 1 1 1 1]
[ 1 2 4 8 16]
[ 1 3 9 27 81]
[ 1 4 16 64 256]
[ 1 5 25 125 625]]