- Start by importing NumPy:
import numpy as np
- Produce a NumPy array of 10 digits, similar to Python's range(10) method:
np.arange(10)array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
- The array looks like a Python list with only one pair of brackets. This means it is of one dimension. Store the array and find out the shape:
array_1 = np.arange(10)array_1.shape(10L,)
- The array has a data attribute, shape. The type of array_1.shape is a tuple (10L,), which has length 1, in this case. The number of dimensions is the same as the length of the tuple—a dimension of 1, in this case:
array_1.ndim #Find number of dimensions of array_11
- The array has 10 elements. Reshape the array by calling the reshape method: