I want to convert (14106, 1, 32, 32, 3) to (14106, 32, 32, 3) using numpy python?
CodePudding user response:
Here is a possible solution (a
being your array):
a = a.squeeze()
or
a = np.squeeze(a)
np.squeeze(a)
simply emoves axes of length one from a. Here you can find the official docs.
CodePudding user response:
You can use squeeze to remove the dimension of 1.
- arr is your NumPy array
- 1 is the dimension index to remove. (in your example it's the second one, so 1). You can use it without specifying the index number then it will remove all the dimensions of size 1 from the array.
arr = numpy.squeeze(arr,1)
NumPy: Remove dimensions of size 1 from ndarray (np.squeeze)