Remove single-dimensional entries from a specified shape using NumPy

In this python numpy program, we will remove single-dimensional entries from a specified shape using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Specify the shape using np.zeros().
  3. Now remove single-dimensional entries from a specified shape using np.squeeze().
  4. 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)
				
			

find the ith element of an array.

convert 1-D arrays as columns into a 2-D array.

Leave a Comment