- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Remove axes of length one from an array over axis 0 in Numpy

Squeeze the Array shape using the **numpy.squeeze()** method. This removes axes of length one from an array over specific axis. The axis is set using the "axis" parameter. We have set axis 0 here.

The function returns the input array, but with all or a subset of the dimensions of length 1 removed. This is always a itself or a view into the input array. If all axes are squeezed, the result is a 0d array and not a scalar.

The axis selects a subset of the entries of length one in the shape. If an axis is selected with shape entry greater than one, an error is raised.

## Steps

At first, import the required library −

import numpy as np

Creating a numpy array using the array() method. We have added elements of int type −

arr = np.array([[[20, 36, 57, 78], [32, 54, 69, 84]]])

Display the array −

print("Our Array...

",arr)

Check the Dimensions −

print("

Dimensions of our Array...

",arr.ndim)

Get the Datatype −

print("

Datatype of our Array object...

",arr.dtype)

Display the shape of array −

print("

Array Shape...

",arr.shape)

Squeeze the Array shape using the numpy.squeeze() method. The axis is set using the "axis" parameter −

print("

Squeeze the shape of Array...

",np.squeeze(arr, axis = 0).shape)

## Example

import numpy as np # Creating a numpy array using the array() method # We have added elements of int type arr = np.array([[[20, 36, 57, 78], [32, 54, 69, 84]]]) # Display the array print("Our Array...

",arr) # Check the Dimensions print("

Dimensions of our Array...

",arr.ndim) # Get the Datatype print("

Datatype of our Array object...

",arr.dtype) # Display the shape of array print("

Array Shape...

",arr.shape) # Squeeze the Array shape using the numpy.squeeze() method # The axis is set using the "axis" parameter print("

Squeeze the shape of Array...

",np.squeeze(arr, axis = 0).shape)

## Output

Our Array... [[[20 36 57 78] [32 54 69 84]]] Dimensions of our Array... 3 Datatype of our Array object... int64 Array Shape... (1, 2, 4) Squeeze the shape of Array... (2, 4)

- Related Questions & Answers
- Remove axes of length one from an array over specific axis in Numpy
- Remove axes of length one from an array in Numpy
- Remove axes of length one with specific axis in Numpy
- Remove axes of length one from the masked array in Numpy
- Expand the shape of an array over axis 0 in Numpy
- Return the average of the masked array elements over axis 0 in Numpy
- Compute the maximum of the masked array elements over axis 0 in Numpy
- Compute the minimum of the masked array elements over axis 0 in Numpy
- Expand the shape of an array over axis 1 in Numpy
- Expand the shape of an array over specific axis in Numpy
- Expand the shape of an array over tuple of axis in Numpy
- Join a sequence of Numpy arrays with stack() over axis 0
- Return the gradient of an N-dimensional array over axis 0 in Python
- Unpack elements of a uint8 array into a binary-valued output array over axis 0 in Numpy
- Return the cumulative product of array elements over axis 0 treating NaNs as one in Python