1.

How will you find the shape of any given NumPy array?

Answer»

We can use the shape attribute of the numpy array to find the shape. It returns the shape of the array in terms of row COUNT and column count of the array.

import numpy as nparr_two_dim = np.array([("x1","X2", "x3","x4"), ("x5","x6", "x7","X8" )])arr_one_dim = np.array([3,2,4,5,6])# find and PRINT shapeprint("2-D Array Shape: ", arr_two_dim.shape)print("1-D Array Shape: ", arr_one_dim.shape)"""Output:2-D Array Shape: (2, 4)1-D Array Shape: (5,)"""


Discussion

No Comment Found