In this python numpy program, we will create a NumPy array and reshape it.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Reshape the given array to 5 rows and 6 columns using reshape.
- Print the output.
import numpy as np
x = np.arange(30)
y = x.reshape(5,6)
print("Array: \n",y)
Output :
Array:
[[ 0 1 2 3 4 5]
[ 6 7 8 9 10 11]
[12 13 14 15 16 17]
[18 19 20 21 22 23]
[24 25 26 27 28 29]]