w3resource logo

:

Python Exercises

Python NumPy: Remove single-dimensional entries from a specified shape

Python NumPy: Array Object Exercise-57 with Solution

Write a Python program to remove single-dimensional entries from a specified shape.
Specified shape: (3, 1, 4).

Sample Solution:-

Python Code:

import numpy as np
x = np.zeros((3, 1, 4))
print(np.squeeze(x).shape)

Sample Output:

(3, 4)

Python Code Editor:

Improve this sample solution and post your code through Disqus