...

/

Array Attributes and Operations

Array Attributes and Operations

Learn about the different array attributes and operations in Python.

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.

Press + to interact
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 ...