numpy.squeeze


Advertisements

This function removes one-dimensional entry from the shape of the given array. Two parameters are required for this function.

numpy.squeeze(arr, axis)

Where,

Sr.No. Parameter & Description
1

arr

Input array

2

axis

int or tuple of int. selects a subset of single dimensional entries in the shape

Example

import numpy as np  
x = np.arange(9).reshape(1,3,3) 

print 'Array X:' 
print x 
print '\n'  
y = np.squeeze(x) 

print 'Array Y:' 
print y 
print '\n'  

print 'The shapes of X and Y array:' 
print x.shape, y.shape

Its output is as follows −

Array X:
[[[0 1 2]
 [3 4 5]
 [6 7 8]]]

Array Y:
[[0 1 2]
 [3 4 5]
 [6 7 8]]

The shapes of X and Y array:
(1, 3, 3) (3, 3)
numpy_array_manipulation.htm
Advertisements