# Generate a Vandermonde matrix and set the number of columns in the output in Numpy

To generate a Vandermonde matrix, use the np.ma.vander() method in Python Numpy. Set the number of columns in the output using the N parameter. If N is not specified, a square array is returned (N = len(x)).

The columns of the output matrix are powers of the input vector. The order of the powers is determined by the increasing boolean argument. Specifically, when increasing is False, the i-th output column is the input vector raised element-wise to the power of N - i - 1. Such a matrix with a geometric progression in each row is named for Alexandre- Theophile Vandermonde.

## Steps

At first, import the required library −

import numpy as np

Create an array with int elements using the numpy.array() method −

arr = np.array([93, 33, 76, 73, 88])
print("Array...", arr)

Create a masked array and mask some of them as invalid −

maskArr = ma.masked_array(arr, mask =[0, 1, 0, 0, 1])
print("Our Masked Array...", maskArr)

Get the type of the masked array −

print("Our Masked Array type...", maskArr.dtype)


Get the dimensions of the Masked Array −

print("Our Masked Array Dimensions...",maskArr.ndim)

Get the shape of the Masked Array −

print("Our Masked Array Shape...",maskArr.shape)


Get the number of elements of the Masked Array −

print("Number of elements in the Masked Array...",maskArr.size)

To generate a Vandermonde matrix, use the np.ma.vander() method in Python Numpy. Set the number of columns in the output using the N parameter. If N is not specified, a square array is returned (N = len(x)) −

N = 4
print("Result...", np.ma.vander(maskArr, N))

## Example

import numpy as np
import numpy.ma as ma

# Create an array with int elements using the numpy.array() method
arr = np.array([93, 33, 76, 73, 88])
print("Array...", arr)

# Create a masked array and mask some of them as invalid

# Get the type of the masked array

# Get the dimensions of the Masked Array

# Get the shape of the Masked Array

# Get the number of elements of the Masked Array

# To generate a Vandermonde matrix, use the np.ma.vander() method in Python Numpy
# Set the number of columns in the output using the N parameter. If N is not specified, a square array is returned (N = len(x))
N = 4
print("Result...", np.ma.vander(maskArr, N))

## Output

Array...
[93 33 76 73 88]

[93 -- 76 73 --]

int64

1

[ 0 0 0 0]]