What is the numpy.vander() function from NumPy in Python?

Overview

The vander() function in Python is simply used to generate a Vandermonde matrix.

Syntax

numpy.vander(x, N=None, increasing=False)

Parameter value

The vander() function takes the following parameter values.

  • x: This represents the 1-D input array.
  • N: This represents the number of columns in the output matrix or array.
  • increasing: This takes a Boolean value and represents the power of the columns. If True, the powers increase from left to right, if False by default, they are reversed.

Return values

The vander() function returns a Vandermonde matrix.

Code example

import numpy as np
# creating an array
myarray = np.array([1, 2, 3, 4, 5])
# implementing the vander() function
mymatrix = np.vander(myarray, N=3, increasing=False)
print(mymatrix)

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We create an array, myarray, having 5 elements.
  • Line 7: We implement the vander() function on the array myarray using 3, as the number of columns of the output array and a default value for the increasing parameter. The output is assigned to a new variable, mymatrix.
  • Line 9: We print the Vandermonde matrix mymatrix.

Free Resources