Numpy Note
Numpy Note
In [22]: B = np.arange(48)
B
In [23]: C = np.zeros((4,4))
C
1
Out[27]: array([[10, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10]])
In [29]: F = np.eye(10)
F
Out[29]: array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 1., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])
2 Array Shape
In [9]: A.shape
Out[9]: (4, 1, 8)
In [20]: B = B.reshape(1, 6, 8)
3 Array Axis
Imagine collapsing the chosen axis
In [12]: A.max()
Out[12]: 31
In [13]: A.max(axis = 0)
In [14]: A.max(axis = 1)
In [15]: A.max(axis = 2)
2
Out[15]: array([[ 7],
[15],
[23],
[31]])
In [162]: a[1, 2]
Out[162]: 6
Out[163]: 11
4.0.2 Subarray
Index Array Form: array[array, array]
Output: 1D array of values with indices (x, y)
Note: return a copy of the subarray
In [176]: a = np.arange(12).reshape(3, 4)
a
3
Slices Form: array[slice, slice]
Output: Array slice with same dimension
Note: return the view of the subarray. use copy() if want a copy
In [192]: a = np.arange(12).reshape(3, 4)
a
In [197]: a = np.arange(12).reshape(3, 4)
a
In [18]: A + B
4
[32, 34, 36, 38, 40, 42, 44, 46],
[40, 42, 44, 46, 48, 50, 52, 54],
[48, 50, 52, 54, 56, 58, 60, 62]],