Useful builtin matrices in Python Numpy | applied electronics engineering


Useful builtin matrices in Python Numpy

By Applied Electronics - Tuesday, March 7, 2017 No Comments
Like in Matlab programming language, there are built in matrices in Python programming language with Numpy which will ease your program coding.Some examples are zeros, ones, empty, eye, identity, full, random, diagonal etc. It was already mentioned the advantage of using numpy package for numerical computation like matrices in How to create matrix in Python.


To create matrix filled with zero elements we can use the zeros() function as follows,


To create matrix filled with ones we can use the ones() function as follows,


The function empty() returns a new array of given shape and type, without initializing entries.


To create identity matrix we can use the eye() function with parameter k = 0. The eye function in python unlike in matlab also supports off diagonal matrices as follows.


identity() function generates a two dimensional identity array.


full lls up particular data into all elemental positions.


To create a random array ( lled up with random numbers), one uses the random function as follows:

The first one a1 is a row vector and the second one a2 is a matrix. Note that the function rand() comes inside the subpackage random.


diag() commands makes an array of de ned dimensions as follows:

No Comment to " Useful builtin matrices in Python Numpy "