From “Quickstart tutorial”:
NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In NumPy dimensions are called axes.
NumPy’s array class is called ndarray – some important attributes listed:
- ndarray.ndim (the number of axes (dimensions) of the array.)
- ndarray.shape (the dimensions of the array – a tuple of integers indicating the size of the array in each dimension – for example – (n,m). The length of the shape tuple is therefore the number of axes, ndim.
- ndarray.size: the total number of elements of the array. This is equal to the product of the elements of shape.
- ndarray.dtype: an object describing the type of the elements in the array. One can create or specify dtype’s using standard Python types. Additionally NumPy provides types of its own. numpy.int32, numpy.int16, and numpy.float64 are some examples.
- ndarray.itemsize: the size in bytes of each element of the array. For example, an array of elements of type float64 has itemsize 8 (=64/8), while one of type complex32 has itemsize 4 (=32/8). It is equivalent to ndarray.dtype.itemsize.
- ndarray.data: the buffer containing the actual elements of the array.
One of the most common ways is to create one from a list or a list like an object by passing it to the np.array function.
# Create an 1d array from a list
import numpy as np
list1 = [0,1,2,3,4]
arr1d = np.array(list1)
# Print the array and its type
#> class ‘numpy.ndarray’
#> array([0, 1, 2, 3, 4])
Checkout the remaining part here.