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 npa1 = np.array([1, 2, 3, 4])a2 = np.array([1.1, 2.2, 3.3, 4.4])print(a1.dtype) # prints int64print(a2.dtype) # prints float64print(a1.itemsize) # prints 8print(a2.itemsize) # prints 8print(a1.nbytes) # prints 32print(a2.nbytes) # prints 32print(a1.data) # prints <memory at 0x7f60b03bda00># Address can be different on your sideprint(a1.strides) # prints (8,)print(a2.data) # prints <memory at 0x7f60b03bda00># Address can be different on your sideprint(a2.strides) # prints (8,)
In the code above, dtype
...