- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 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))
Output
Array... [93 33 76 73 88] Our Masked Array... [93 -- 76 73 --] Our Masked Array type... int64 Our Masked Array Dimensions... 1 Our Masked Array Shape... (5,) Number of elements in the Masked Array... 5 Result.. . [[804357 8649 93 1] [ 0 0 0 0] [438976 5776 76 1] [389017 5329 73 1] [ 0 0 0 0]]
- Related Articles
- Generate a Vandermonde matrix in Numpy
- Generate a Vandermonde matrix of the Laguerre polynomial in Python
- Generate a Vandermonde matrix of the Hermite polynomial in Python
- Generate a Vandermonde matrix of the Chebyshev polynomial in Python
- Generate a Vandermonde matrix of the Legendre series in Python
- Generate a Vandermonde matrix of the Hermite_e polynomial in Python
- Generate a Pseudo Vandermonde matrix of the Hermite polynomial in Python
- Generate a pseudo Vandermonde matrix of the Chebyshev polynomial in Python
- Generate a Pseudo Vandermonde matrix of the Hermite_e polynomial in Python
- Finding the number of rows and columns in a given matrix using Numpy
- Generate a Vandermonde matrix of given degree in Python
- Generate a Pseudo-Vandermonde matrix of given degree in Python
- Generate a Pseudo Vandermonde matrix of the Laguerre polynomial and x, y array of points in Python
- Generate a Pseudo Vandermonde matrix of the Legendre polynomial and x, y array of points in Python
- Generate a Vandermonde matrix of the Laguerre polynomial with float array of points in Python
