Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python NumPy squeeze function Example

# welcome to softhunt.net
# Python program explaining
# numpy.squeeze function

import numpy as np

in_arr = np.array([[[1, 2, 3], [4, 5, 6]]])

print ("Input array : 
", in_arr)
print("Shape of input array : ", in_arr.shape)

out_arr = np.squeeze(in_arr)

print ("output squeezed array : 
", out_arr)
print("Shape of output array : ", out_arr.shape)
Comment

.squeeze function in numpy

The squeeze() function is used to remove single-dimensional entries from the
shape of an array.
Comment

Python NumPy squeeze function Syntax

numpy.squeeze(arr, axis=None )
Comment

Python NumPy squeeze function Example with axis

# welcome to softhunt.net
# Python program explaining
# numpy.squeeze function
import numpy as geek
in_arr = geek.arange(9).reshape(1, 3, 3)

print ("Input array : 
", in_arr)
out_arr = geek.squeeze(in_arr, axis = 0)

print ("output array : 
", out_arr)
print("The shapes of Input and Output array : ",in_arr.shape, out_arr.shape)
Comment

Python NumPy squeeze function Example with axis=1

# welcome to softhunt.net
# Python program explaining
# numpy.squeeze function
import numpy as geek
in_arr = geek.arange(9).reshape(1, 3, 3)

print ("Input array : 
", in_arr)
out_arr = geek.squeeze(in_arr, axis = 1)

print ("output array : 
", out_arr)
print("The shapes of Input and Output array : ",in_arr.shape, out_arr.shape)
Comment

PREVIOUS NEXT
Code Example
Python :: Python NumPy broadcast_arrays() Function Syntax 
Python :: Python NumPy atleast_3d Function Syntax 
Python :: Python NumPy atleast_2d Function Example when inputs are in high dimension 
Python :: Python NumPy rollaxis Function Example 
Python :: Python NumPy Shape function example verifying the value of last dimension 
Python :: python antigravity 
Python :: python f strings 
Python :: how to extract a list of values from numpy array using index list 
Python :: Python NumPy asanyarray Function Example List to an array 
Python :: Python NumPy asscalar Function Example 02 
Python :: Python NumPy row_stack Function Example with 1d array 
Python :: python locateonscreen method 
Python :: python os.listdir attributes 
Python :: pandas dt.weekday to string 
Python :: Exception has occurred: FileNotFoundError 
Python :: python service linux 
Python :: Create a list of multiples of 3 from 0 to 20. 
Python :: how to do something daily python 
Python :: python override inherited method class model constructor 
Python :: how to show all rows whith a unique value in a column 
Python :: extract numbers from image python 
Python :: torch view vs unsqueeze 
Python :: send by email in odoo 14 
Python :: kaggle set utility script 
Python :: lxml etree fromstring find 
Python :: Flask error: werkzeug.routing.BuildError 
Python :: walrus with ternary python 
Python :: element tree no able to find tag 
Python :: can you make a class in a class python 
Python :: get correlation between two signals 1d scipy 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =