Tuesday , March 19 2024
Inspect an Array

Inspect an Array

4 – Inspect an Array

Inspect NumPy Array

In [2]:
import numpy as np
In [3]:
arr = np.array([[1,2,3], [4,5,6]], dtype=np.int64)
arr
Out[3]:
array([[1, 2, 3],
       [4, 5, 6]], dtype=int64)

Inspect general information of an array

In [4]:
print(np.info(arr))
class:  ndarray
shape:  (2, 3)
strides:  (24, 8)
itemsize:  8
aligned:  True
contiguous:  True
fortran:  False
data pointer: 0x451f310
byteorder:  little
byteswap:  False
type: int64
None

Inspect the data type of an array

In [5]:
print(arr.dtype)
int64

Inspect the dimension of an array

In [6]:
print(arr.shape)
(2, 3)

Inspect length of an array

In [7]:
print(len(arr))
2

Inspect the number of dimensions of an array

In [8]:
print(arr.ndim)
2

Inspect the number of elements in an array

In [9]:
print(arr.size)
6

Inspect the number of bytes of each element in an array

In [10]:
print(arr.itemsize)
8

Inspect the memory size of an array (in byte)

In [11]:
# arr.nbytes = arr.size * arr.itemsize
print(arr.nbytes)
48

About Machine Learning

Check Also

Combining and Merging in Pandas - Data Science Tutorials

Combining and Merging in Pandas – Data Science Tutorials

13- Combining and Merging Combining and Merging in Pandas¶The datasets you want to analyze can …

Leave a Reply

Your email address will not be published. Required fields are marked *