411 REFERENCE · Wikibooks
An Introduction to Python For Undergraduate Engineers/Matrices
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Matrices can be created in the following way:
mymatrix = Matrix([[1,2],[3,4]])
In this example, [1,2] produces the first line of the matrix and [2,3] creates the second.
Quick Standard Matrices
The following built in functions can be used to quickly create some standard matrices of specified size.
Command Description Exampleeye()Identity Matrixeye(4) creates a 4x4 identity matrixzeros()Empty Matrixzeros(2,3) creates a 2x3 matrix of zerosones()Matrix of 1sones(2) creates a 2x2 matrix of ones
Getting the Size of a Matrix
You can find out the size of a matrix using the .shape[] command, for example:
mymatrix.shape[0]
Command Description.shape[0]Gives number of rows.shape[1]Gives number of columns