Get Array Size - NumPy


NumPy - Array size

In NumPy, array size is defined as the total number of elements in the array.

To get the size of a numpy array, we can read the size property of the array object.

For example, if arr is the numpy array, then arr.size returns the size of the array.

Examples

1. Get size of an array with shape (3, 5)

In the following program, we take a numpy array of shape (3, 5), and get its size programmatically using size property.

Python Program

import numpy as np

arr = np.ones((3, 5))
size = arr.size
print(size)

Output

15

2. Get size of an array with shape (3, 5, 16)

In the following program, we take a numpy array of shape (3, 5, 16), and get its size programmatically using size property.

Python Program

import numpy as np

arr = np.ones((3, 5, 16))
size = arr.size
print(size)

Output

240

Summary

In this NumPy Tutorial, we learned how to get the size of a numpy array in Python using size property of array object.