The easiest explanation of NumPy is here | Python | NumPy

NumPy-Python

Hello! Everyone in this I will tell you about all the most important module of Python

If you are going for DATA SCIENCE, MACHINE LEARNING OR ARTIFICIAL INTELLIGENCE then it is the thing which should be always with you in your pocket.

So, without any further delay lets start the easiest explanation on Numpy.

What is NumPy?

NumPy is a library for scientific computing in Python Language, which stands for Numerical Python. It provides you with the high-performance multidimensional array. It provides the best operations to apply the array. It is the most basic requirement for AI, ML, DL, and Data Science. It is an open-source library so that anyone can use it. So, Let's begin with the implementation. If you are not aware of python language wanna free course, you can click here.

First of all, import your library like this...

import numpy as np

You can use any keyword in the place of "np",  it is the standard one that's why we are using it.

Now, let's begin with the multi-dimensional array in NumPy

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

Output:

[1, 2, 3]

Example:

# more than one dimensions 
import numpy as np 
a = np.array([[1, 2], [3, 4]]) 
print a

Output:

[[1, 2] 
 [3, 4]]

Example:

# minimum dimensions 
import numpy as np 
a = np.array([1, 2, 3,4,5], ndmin = 2) 
print a

Output:

[[1, 2, 3, 4, 5]]

Example:

# dtype parameter 
import numpy as np 
a = np.array([1, 2, 3], dtype = complex) 
print a

Output:

[ 1.+0.j,  2.+0.j,  3.+0.j]

Some other uses of NumPy:

1. Find the dimension of the array.

import numpy as np 
a = np.array([[1,2,3],[4,5,6]]) 
print a.shape

Output:

(2, 3)


2. Return the byte-size of each element in an array.

# dtype of array is int8 (1 byte) 
import numpy as np 
x = np.array([1,2,3,4,5], dtype = np.int8) 
print x.itemsize

Output:

1

Example:

# dtype of array is now float32 (4 bytes) 
import numpy as np 
x = np.array([1,2,3,4,5], dtype = np.float32) 
print x.itemsize

Output:

4


3. Find the data type of the elements in the array.

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

Output:

int32

4. Reshaping an Array.

import numpy as np
a=np.array([1,2,3,4,5],[6,7,8,9,0])
a=a.reshape(5,2)
print(a)

Output:

[[1,6]
 [2,7]
 [3,8]
 [4,9]
 [5,0]]


5. Printing array from numerical ranges:

#numpy.arange(start, stop, step, dtype)

Example:

import numpy as np 
x = np.arange(5) 
print x

Output:

[0  1  2  3  4]

Example:

import numpy as np 
# dtype set 
x = np.arange(5, dtype = float)
print x

Output:

[0.  1.  2.  3.  4.] 

Example:

# start and stop parameters set 
import numpy as np 
x = np.arange(10,20,2) 
print x

Output:

[10  12  14  16  18] 


6. Slicing in an array with the help of Numpy.

Slicing: return the specified part of the whole array.

Example:

#slice(start,stop,step)
import numpy as np 
a = np.arange(10) 
s = slice(2,7,2) 
print a[s]

Output:

[2  4  6]


Example:

# slice single item by putting the single element 
import numpy as np 
a = np.arange(10) 
b = a[5] 
print b

Output:

5

Example:

# slice items starting from index 
import numpy as np 
a = np.arange(10) 
print a[2:]

Output:

[2  3  4  5  6  7  8  9]


This Blog will continue to the pandas and preprocessing of data to use in machine learning.









Comments

Popular posts from this blog

SMART HOSPITAL | IoT based smart health monitoring system | Real time responses | Internet Of Things | ESP8266

A Quick Guide to Data pre-processing for Machine Learning | Python | IMPUTATION | STANDARDISATION | Data Analysis | Data Science

Plotly & Cufflinks | A Data Visualisation Library with Modern Features | Python | Data Science | Data Visualisation