numpy.squeeze() in Python

The numpy.squeeze() function removes single-dimensional entries from the shape of an array.

Syntax

Parameter

The numpy.squeeze() function has three parameters which are as follows:

a: It represents the Input data.

axis: This parameter signifies an int or tuple of int values. It selects a subset of the single-dimensional entries in the shape. If an axis is selected with shape entry greater than one, an error is raised.

Return

This function returns an input array, but with all or a subset of the dimensions of length 1 removed.

Example 1

Output

Example 2

Output

Pin It on Pinterest

Share This