Difference between reshape() and resize() method in Numpy
Last Updated :
05 Sep, 2020
Both the numpy.reshape() and numpy.resize() methods are used to change the size of a NumPy array. The difference between them is that the reshape() does not changes the original array but only returns the changed array, whereas the resize() method returns nothing and directly changes the original array.
Example 1: Using reshape()
Python3
import numpy as np
gfg = np.array([ 1 , 2 , 3 , 4 , 5 , 6 ])
print ( "Original array:" )
display(gfg)
print ( "Changed array" )
display(gfg.reshape( 2 , 3 ))
print ( "Original array:" )
display(gfg)
|
Output:
Example 2: Using resize()
Python3
import numpy as np
gfg = np.array([ 1 , 2 , 3 , 4 , 5 , 6 ])
print ( "Original array:" )
display(gfg)
print ( "Changed array" )
display(gfg.resize( 2 , 3 ))
print ( "Original array:" )
display(gfg)
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...