```python
import numpy as np
```

### Matrices


```python
matrix_01 = np.matrix("1, 2, 3; 4, 5, 6"); matrix_01
```




    matrix([[1, 2, 3],
            [4, 5, 6]])




```python
matrix_02 = np.matrix([[1, 2, 3], [4, 5, 6]]); matrix_02
```




    matrix([[1, 2, 3],
            [4, 5, 6]])



### Math Operations with Arrays and Matrices


```python
array_01 = np.array([[1, 2], [3, 4]]); array_01
```




    array([[1, 2],
           [3, 4]])




```python
type(array_01)
```




    numpy.ndarray




```python
array_01 * array_01
```




    array([[ 1,  4],
           [ 9, 16]])




```python
matrix_01 = np.mat(array_01); matrix_01
```




    matrix([[1, 2],
            [3, 4]])




```python
type(matrix_01)
```




    numpy.matrix




```python
matrix_01 * matrix_01
```




    matrix([[ 7, 10],
            [15, 22]])



### The multiplications results between arrays and matrices are different. The math is the following:

## $$  \boxed{ \begin{align} \begin{pmatrix} 1 & 2    \\ 3 &  4   \end{pmatrix} & \begin{pmatrix} 1 & 2    \\ 3 &  4   \end{pmatrix}  = \begin{pmatrix} 7 & 10    \\ 15 &  22   \end{pmatrix} \end{align} }$$

### A matrix apply the multiplication from lines to columns, resulting in the following operations:


```python
from IPython.display import Image
Image('aux/images/matrix-multiplication.png')
```

### To do the same operation with an array object:


```python
array_01 = np.array([[1, 2], [3, 4]]); array_01
```




    array([[1, 2],
           [3, 4]])




```python
np.dot(array_01, array_01)
```




    array([[ 7, 10],
           [15, 22]])



### Conversions


```python
array_01 = np.array([[1, 2], [3, 4]]); array_01
```




    array([[1, 2],
           [3, 4]])




```python
# Array to Matrix
matrix_01 = np.asmatrix(array_01); matrix_01
```




    matrix([[1, 2],
            [3, 4]])




```python
# Matrix to Array
array_02 = np.asarray(matrix_01); array_02
```




    array([[1, 2],
           [3, 4]])



b801552fa4e6a7665d76c23257067f5306883fc5
ipynb
Jupyter Notebook
modules/02-data-organization-and-visualization/06-numpy-array-matrix-math-operations.ipynb
cfascina/rtaps
d54c83a2100ac3a300041e2d589c86e5ca0c4a8e
MIT
2020-07-27T14:25:23.000Z
2020-12-02T22:12:03.000Z
modules/02-data-organization-and-visualization/06-numpy-array-matrix-math-operations.ipynb
cfascina/rtaps
d54c83a2100ac3a300041e2d589c86e5ca0c4a8e
MIT
modules/02-data-organization-and-visualization/06-numpy-array-matrix-math-operations.ipynb
cfascina/rtaps
d54c83a2100ac3a300041e2d589c86e5ca0c4a8e
MIT
Qwen/Qwen-72B
1. YES
2. YES