Search⌘ K

Array Attributes and Operations

Explore key attributes of NumPy arrays, including element type, size, and shape. Learn to perform fast and compact arithmetic, statistical, linear algebra, bitwise, and comparison operations to handle array data effectively.

We'll cover the following...

Array attributes

A NumPy array has several attributes that indicate the element type, element size, shape of the array, size of the array, etc.

We can obtain the type of elements present in a NumPy array, their sizes, their location in memory, etc.

Python 3.8
import numpy as np
a1 = np.array([1, 2, 3, 4])
a2 = np.array([1.1, 2.2, 3.3, 4.4])
print(a1.dtype) # prints int64
print(a2.dtype) # prints float64
print(a1.itemsize) # prints 8
print(a2.itemsize) # prints 8
print(a1.nbytes) # prints 32
print(a2.nbytes) # prints 32
print(a1.data) # prints <memory at 0x7f60b03bda00>
# Address can be different on your side
print(a1.strides) # prints (8,)
print(a2.data) # prints <memory at 0x7f60b03bda00>
# Address can be different on your side
print(a2.strides) # prints (8,)

In the code above, dtype ...