Friday, September 5, 2025
HomeLanguagesDifference between reshape() and resize() method in Numpy

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




# 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)


       

Output:

      

Example 2: Using resize()

Python3




# 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)


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS