Learn Python

Learn Data Structure & Algorithm

Numpy Introduction

Numpy Array

Numpy Attributes

Numpy generate random numbers

Numpy Slicing

Numpy Concatenate & split

Numpy Insert & delete

Numpy Math

Numpy Condition

Numpy Reshaping

Learn Pandas

Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

Learn MySQL

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Most used numpy attributes

ndim attribute

To find matrix dimension ndim is used. At first, write the matrix variable name and then .ndim attribute. By doing this you will get the dimension of the matrix.

Example:

Example:
Input
import numpy as np
x=[[1,2],[3,4]]
y=np.array(x)
z=y.ndim
print(z)
Output
2

shape attribute

To find the matrix shape, shape attribute is used. At first, write the matrix variable name and then .shape.

Example:

Input
import numpy as np
x=[[1,2],[3,4]]
y=np.array(x)
z=y.shape
print(z)
Output
(2,2)

dtype attribute

To find matrix data type, this attribute is used. First, write the matrix variable name then .dtype.

Example:

Input
import numpy as np
x=[[1,2],[3,4]]
y=np.array(x)
z=y.dtype
print(z)
Output
int32

size attribute

Size attribute shows the total number of elements present in the array.

Example:

Input
import numpy as np
x=[[1,2],[3,4]]
y=np.array(x)
z=y.size
print(z)
Output
4

itemsize attribute

This attribute shows each element size in bites, present in the array.

Example:

Input
import numpy as np
x=[[1,2],[3,4],[5,6]]
y=np.array(x)
z=y.size
print(z)
Output
6

Flatten method

Flatten method converts 2D,3D, or any dimension array into one dimension array.

Example:

Input
import numpy as np
x=np.array([[1,2,3],[4,5,6],[7,8,9]])
z=np.array([[[1,2,3],[4,5,6],[7,8,9]]])
y=x.flatten()
v=z.flatten()
print(y)
print(v)
Output
array([1,2,3,4,5,6,7,8,9])
array([1,2,3,4,5,6,7,8,9])

Transpose() function

Transpose function converts all the columns into rows and all rows into columns.

Example:

Input
import numpy as np
x=np.array([[1,2,3],[4,5,6],[7,8,9]])
y=x.transpose()
print(y)
Output
[[1 4 7]
[2 5 8]
[3 6 9]]

Unique attribute

Unique attribute will print the unique values of the given array.

Example:

Input
import numpy as np
x=np.array([[1,1,3],[4,3,5],[7,8,9]])
y=np.unique(x)
print(y)
Output
[1 3 4 5 7 8 9]

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.