當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python numpy.vander()用法及代碼示例


numpy.vander()函數用於生成Vandermonde矩陣。

用法: numpy.vander(arr, N = None, increasing = False)
參數:
arr :[ array_like] 1-D input array.
N :[int, optional] Number of columns in the output. If N is not specified, a square array is returned (N = len(x)).
increasing :[bool, optional] Order of the powers of the columns. If True, the powers increase from left to right, if False (the default) they are reversed.
Return :[ndarray] dVandermonde matrix. If increasing is False, the first column is x^(N-1), the second x^(N-2) and so forth. If increasing is True, the columns are 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]]



相關用法


注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.vander() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。