remove axis numpy array 1

remove axis numpy array

x = np.array([[[0], [1], [2]]])
x.shape
(1, 3, 1)
np.squeeze(x).shape
(3,)
np.squeeze(x, axis=0).shape
(3, 1)
np.squeeze(x, axis=1).shape

Here is what the above code is Doing:
1. x is a 3D array with shape (1, 3, 1).
2. np.squeeze(x) removes single-dimensional entries from the shape of x.
3. np.squeeze(x, axis=0) removes single-dimensional entries from the shape of x along axis 0.
4. np.squeeze(x, axis=1) removes single-dimensional entries from the shape of x along axis 1.

Similar Posts