NumPy library in Python for data science:
NumPy is the short form of Numerical Python. Many other libraries rely on NumPy. It has functions to work with arrays and it used for various mathematical operations like linear algebra, Fourier transform and matrices. So NumPy is one of the most important libraries for data science.
Installation and getting started:
By default it doesn’t come with python, so before using it has to be installed. Easiest way is to install Anaconda, so that it comes with other packages or go to your command prompt and type pip install numpy.
For getting started you have to import the library. So you have to write the following code
Import numpy as np
Difference between python list and NumPy array:
NumPy is a type of python list. The difference is NumPy is efficient and faster than list. When the data is larger n-dimensional array can be stored in NumPy.
Creating NumPy array:
Creating numpy array |
Here the dimension of the array is 3,4 and the size of the array is 12.
Elements of numpy array |
The elements in the array can be of integer or float type.
Creating arrays with zeros:

Creating numpy array with zero
Creating arrays with ones:
Creating numpy array with ones |
Creating random arrays:

Creating random arrays
Creating random arrays with specified range:
Creating random arrays with specified range |
Arithmetic operations in NumPy in Python:
Addition and Subtraction:
Multiplication and division:
Power:
Mod and Remainder:
Absolute value:
0 Comments