In Numpy and Python everything that is created are objects and objects have functions and attributes. For examples, the matrices and arrays created are objects. In the previous post we showed some examples of numpy array and matrices.

Here we will check attributes of array and matrices in Numpy. The following shows how to create a 1D array and check some of its attributes.

First create an array of one dimensional.

After that we can check the various properties of this array A1 as follows:

The first is the ndim property which gives the dimension of the array or matrices. Since A1 is a one dimensional array we get one for this. The size property gives the number of elements which is 3. The nbytes gives the total byte consumed by the array which is 12 because each int32 consumes 4 bytes in python. Then we have the dtype attribute which gives us the data type of the elements of the array. Here we have int32 data type integer. This is default integer data type and depends on which bit version computer you are running the numpy.

Similarly we can check the attributes of matrices in Numpy. Notice that attributes does not have the brackets ( ) as in case of functions.

Also in python IDEs like pycharm, you can get help on various attributes that are available. After you hit the dot you will see a window with list of attributes.

Here we will check attributes of array and matrices in Numpy. The following shows how to create a 1D array and check some of its attributes.

First create an array of one dimensional.

import numpy as np A1 = np.array([1,2,3]) print(A1)

output:

[1 2 3]

After that we can check the various properties of this array A1 as follows:

print(A1.ndim) print(A1.size) print(A1.nbytes) print(A1.dtype)

output:

1 3 12 int32

The first is the ndim property which gives the dimension of the array or matrices. Since A1 is a one dimensional array we get one for this. The size property gives the number of elements which is 3. The nbytes gives the total byte consumed by the array which is 12 because each int32 consumes 4 bytes in python. Then we have the dtype attribute which gives us the data type of the elements of the array. Here we have int32 data type integer. This is default integer data type and depends on which bit version computer you are running the numpy.

Similarly we can check the attributes of matrices in Numpy. Notice that attributes does not have the brackets ( ) as in case of functions.

Also in python IDEs like pycharm, you can get help on various attributes that are available. After you hit the dot you will see a window with list of attributes.

## No Comment to " How to check the attributes of objects in Numpy "