Program to create a NumPy array and reshape it

In this python numpy program, we will create a NumPy array and reshape it.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Reshape the given array to 5 rows and 6 columns using reshape.
  4. 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]]
				
			

convert an array to a data frame with headers.

check whether the dimensions of two arrays are the same or not.

Leave a Comment