Matrices
Data is generally composed of rows, and each row contains the same number of columns. Data is often represented as a two-dimensional grid containing lots of numbers. It can also be interpreted as a list of lists, or a NumPy array of NumPy arrays.
In mathematics, a matrix is a rectangular array of numbers defined by the number of rows and columns. It is standard to list rows first, and columns second. For instance, a 2 x 3 matrix consists of 2 rows and 3 columns, whereas a 3 x 2 matrix consists of 3 rows and 2 columns.
Here is a 4 x 4 matrix:
Figure 10.1 – Matrix representation of a 4 x 4 matrix
Exercise 133 – working with matrices
NumPy has several methods for creating matrices or n-dimensional arrays. One option is to place random numbers between 0 and 1 into each entry.
In this exercise, you will implement various numpy
matrix methods and observe the outputs (recall that random.seed
will allow us to reproduce the same numbers...