reshape()
https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html
Gives a new shape to an array without changing its data.
在不改变数据的情况下,进行数组的变形,变成你想要的n行n列。
1 | import numpy as np |
newaxis()
https://stackoverflow.com/questions/29241056/how-does-numpy-newaxis-work-and-when-to-use-it
newaxis()可使当前数组的维度增加一个维度(dimension)。
- 1D array 会变成 2D array
- 2D array 会变成 3D array
- 3D array 会变成 4D array
- 4D array 会变成 5D array
1 | x1 = np.arange(1,10).reshape(3,3) |
切片操作中利用newaxis():
1 | x1_new = x1[:,np.newaxis] |
书上的例子
1 | x = np.array([1, 2, 3]) |