Introduction to Numpy Library in Python
Introduction
NUMPY stands for Numerical Python. Numpy is one of the libraries for the python programming language. It is used for high level mathematical calculations. It has the large collection of functions for working with the multi-dimensional arrays, matrices, linear algebra, Fourier transform, etc.
Installation of Numpy
#installation of NUMPY using PIP
pip install numpy
(OR)
#installation of NUMPY using CONDA
conda install numpy
3. Now, NUMPY installed on your system. To verify that use the command below.
#check for version of NUMPY
numpy --version
Tip : Use Anaconda Navigator, it comes with built-in software of JUPYTER NOTEBOOKS and pre-installed packages like Numpy, Pandas, Scipy, etc.
Comparison of Lists and Numpy
In Python lists, we can multiply the 2-dimensional matrices with the help of loops.
for (i = 0; i < rows; i++): {
for (j = 0; j < columns; j++): {
c[i][j] = a[i][j]*b[i][j];
}
}
In Numpy ndarray, we can easily multiply arrays with faster execution and simply by,
c = a * b
How to import Numpy in your program?
It is very simple to import Numpy to our program. Follow the code below.
Recommended by LinkedIn
import numpy
Also we can give alias name to the Numpy package.
import numpy as np
Examples
Sample program using Numpy
import numpy as np
maths = np.array([90, 67, 98, 100, 37])
science = np.array([100, 87, 47, 89, 45])
print("Maths marks : \n", maths)
print("Science marks : \n", science)
student_marks = np.array([maths, science], dtype = int)
print("Student marks of Maths and Science : \n", student_marks)
Output
Maths marks :
[ 90 67 98 100 37]
Science marks :
[100 87 47 89 45]
Student marks of Maths and Science :
[[ 90 67 98 100 37]
[100 87 47 89 45]]
Conclusion
Numpy is an vectorized code which provides more concise and easy to read. Let us explore the all Numpy functions on upcoming articles.
Follow on LinkedIn - Trillionaire TK
Follow on Instagram - Trillionaire TK
Visit our website - Information Technology
Learn, Code, Practice!!!