Description : NumPy generally stands for Numerical Python and it is a general-purpose array processing package.it always provides a high-performance multidimensional array object. Numpy is usually for creating an array of n dimensions.
Method Name : matrix.resize(shape)
Description: Resizing matrix means we are able to resize the shape of the given matrix. This function gives a new shape to an array without changing the data. In this article, we will know the difference reshape and resizing as we know that reshaping an array changes its shape as temporary but when we say about resize then the changes are made permanently.
In one of the examples of this article we are resizing the array of that shape which is a type of out of bound value .now NumPy handles this situation to append the zeros when the values have not existed in the array.
Return:
new resized matrix
Parameter : arr
Description :Input array to be resized
Parameter : shape
Description :New shape of the resulting array
The first step would be to give syntax
command:
matrix.resize(shape)
import numpy as np
a = np.array([[3,2,1],[6,5,4]])
print ('First array:')
print (a)
print ('\n')
print ('The shape of first array:')
print (a.shape)
print ('\n' )
b = np.resize(a, (3,2))
print ('second array:' )
print(b)
print ('\n') ,
print ('The shape of second array:' )
print( b.shape )
print ('\n' )
print ('Resize the second array:' )
b = np.resize(a,(3,3))
print( b)
Output :
Comments