Saturday , July 27 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

Groupby in Pandas - Data Science Tutorials

Groupby in Pandas – Data Science Tutorials

14- Groupby Groupby in Pandas¶Pandas groupby is used for grouping the data according to the …

Leave a Reply

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