In this python numpy program, we will remove single-dimensional entries from a specified shape using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Specify the shape using np.zeros().
- Now remove single-dimensional entries from a specified shape using np.squeeze().
- Print the output.
import numpy as np
x = np.zeros((2,1,3))
print("After removing single-dimensional entries: ",
np.squeeze(x).shape)
Output :
After removing single-dimensional entries: (2, 3)