numpy size of array code example

Example 1: numpy array length

np_array.size

Example 2: python numpy array size of n

numpy.array([0] * n) #creates an int64 numpy array of size n with each element having a vaule of 0
numpy.array([0] * n, dtype = '<type>') #creates a numpy array of size n with a type of <type>

Example 3: numpy number of elements

import numpy as np
x = np.array([1,2,3], dtype=np.float64)
print("Size of the array: ", x.size)
print("Length of one array element in bytes: ", x.itemsize)
print("Total bytes consumed by the elements of the array: ", x.nbytes)