Difference between reshape() and resize() method in Numpy

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

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import numpy as np 
    
# creating an array 
gfg = np.array([1, 2, 3, 4, 5, 6]) 
print("Original array:")
display(gfg)  
  
# using reshape()
print("Changed array")
display(gfg.reshape(2, 3)) 
    
print("Original array:")
display(gfg)

chevron_right


       

Output:



      

Example 2: Using resize()

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import numpy as np 
    
# creating an array 
gfg = np.array([1, 2, 3, 4, 5, 6]) 
print("Original array:")
display(gfg)  
  
# using resize()
print("Changed array")
# this will print nothing as None is returned
display(gfg.resize(2, 3)) 
    
print("Original array:")
display(gfg)

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.