×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python | Vandermonde Matrix

Vandermonde Matrix in Python: Here, we are going to learn about the vandermonde matrix and its implementation in Python.
Submitted by Anuj Singh, on July 17, 2020

A Vandermonde Matrix is a square matrix (having size nxn), if and only if there are scalars, x1, x2 , x3,…, xn  such that,

vandermonde matrix in Python

Source: https://en.wikipedia.org/wiki/Vandermonde_matrix

Python numpy package allows us to create a Vandermonde Matrix by providing an inbuilt function numpy.vander().

Python code for vandermonde matrix

# Linear Algebra Learning Sequence
# Vandermonde Matrix

import numpy as np

x = np.array([1, 2, 3, 5])
N = 3
v1 = np.vander(x)

print('Vector x :\n', x)
print('Vandermonde Matrix of vector x', v1)

y = np.array([4,5,6,7,8,9])
N = 4
v2 = np.vander(y, N)
v3 = np.vander(y)

print('\n\nVector y :\n', y)
print('Vandermonde Matrix of vector y (N = 4): ', v2)
print('\n\n Vandermonde Matrix (Square) of vector y : ', v3)

Output:

Vector x :
 [1 2 3 5]
Vandermonde Matrix of vector x [[  1   1   1   1]
 [  8   4   2   1]
 [ 27   9   3   1]
 [125  25   5   1]]


Vector y :
 [4 5 6 7 8 9]
Vandermonde Matrix of vector y (N = 4):  [[ 64  16   4   1]
 [125  25   5   1]
 [216  36   6   1]
 [343  49   7   1]
 [512  64   8   1]
 [729  81   9   1]]


 Vandermonde Matrix (Square) of vector y :  [[ 1024   256    64    16     4     1]
 [ 3125   625   125    25     5     1]
 [ 7776  1296   216    36     6     1]
 [16807  2401   343    49     7     1]
 [32768  4096   512    64     8     1]
 [59049  6561   729    81     9     1]]
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.