You can use NumPy .reshape() function to reshape a NumPy array.

The syntax for reshaping an array in NumPy:

array_variable.reshape(shape)

The following syntax can be demonstrated using examples in Python:

import numpy as np

array_variable = np.array([1,2,3,4])

array_variable.reshape((2,2))

Here is another example,

array_variable = np.array([[1,2],[3,4]])

array_variable.reshape(4)

This is how you reshape a NumPy array.

In Conclusion

Do you have any problems reshaping a NumPy array? Let us know in the comment section below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here