Python 中的 numpy.vander 方法
numpy.vander() 方法用于生成范德蒙德 (Vander) 矩阵。范德蒙德矩阵在每一行都包含一个等比数列,例如:
$$\mathrm{A =\begin{bmatrix}1 & 2 & 4 \1 & 3 & 9 \1 & 5 &25\end{bmatrix} or\: B = \begin{bmatrix}1 & 4 & 16 \1 & 6 &36 \end{bmatrix}}$$
语法
语法如下 −
numpy.vander(x, N=None, increasing=False)
参数
它接受以下参数 −
x - 这是输入数组。
N - 这是输出中的列数。默认为 None。
Increasing - 如果 increasing=True,则幂会从左到右递增。如果 increasing=False,则幂会倒过来。
示例 1
让我们考虑以下示例 −
# import numpy library
import numpy as np
# create an array
a = np.array([11, 12, 13])
print("Input Array :", a)
# Vander function
x = np.vander(a)
print("Vander Elements:
", x)输出
它将生成以下输出 −
Input Array : [11 12 13] Vander Elements: [[121 11 1] [144 12 1] [169 13 1]]
示例 2
我们再来看一个示例 −
# import numpy library
import numpy as np
# create an array
x = np.array([4, 5, 9])
print("Input Array :", x)
# vander function
y = np.vander(x, increasing=True)
print("Vander Elements:
", y)输出
它将生成以下输出 −
Input Array : [4 5 9] Vander Elements: [[ 1 4 16] [ 1 5 25] [ 1 9 81]]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP