NumPy is an extremely popular Python Module used for scientific computing. It is a general-purpose array-processing package which provides a high-performance multidimensional array object, and tools for working with these arrays.
For example: Let's take the medical field, where all the services thrive to improve the patient’s health with minimum costs. Use cases of ML(Machine Learning) are being used to make near perfect diagnoses, recommend best medicines, predict re-admissions and identify high-risk patients. These predictions are based on the dataset of patient records and symptoms exhibited by a patient. To handle this extensive data set and finding out the results, NumPy techniques are used along with other Python libraries like Pandas, Matplotlib.
So, the question arises why it is so popular ??
- It is widely used in scientific computing, data mining, data analysis, machine learning etc.
- Provides Sophisticated (broadcasting) functions.
- It has a powerful command over the N-dimensional object.
- It gifts users, the tools for integrating C/C++ and Fortran code.
- It's loaded with useful random numbers, linear algebra, and Fourier transform capabilities.
How to install it ?
There are many ways to install NumPy in your system. We will cover the default one in this tutorial along with the one using Anaconda.
So let's start with the default one. You must have Python (2.7 or 3) installed on your system. If you do not have Python installed, do not worry, this tutorial will guide you how to stepwise install python on your system.
Python installation brings along pip with it. If you had python installed already then upgrade the version of pip, by running the following command:
pip install pip --upgrade
NumPy package is officially distributed in form wheel of NumPy Build. You can download it from the following source:
Once you have the download the wheel file, use the following command to start the installation of NumPy package.
pip install "COMPLETE-NAME-OF-WHEEL-FILE”
This will install the NumPy package on your system. If you face any trouble installing NumPy package this way, then you can try using Anaconda.
If you are familiar with or already using Anaconda, then follow the below steps to install NumPy package. (Even if you do not know about Anaconda, try downloading it and setting it up, follow this link for that.)
Check whether you have numpy module included to the anaconda environment, run the following command to check that:
conda list
If you do not see numpy listed, this confirms that the default Anaconda installation didn't bring NumPy module along. (some versions do include NumPy module by default). Run the following command to install it:
conda install -c anaconda numpy
Time to see NumPy work
Open up your Python Shell and let's play around a bit with the new NumPy package
The big question is, How to use NumPy arrays? Do not worry, below is a simple program to demonstrate that:
import numpy as np
ar = np.array([2, 4, 6])
arr
Output:
array([2, 4, 6])
# You can access NumPy array elements using index values just like lists in Python
arr[0]
arr[1]
Output:
2
4
Next tutorial: How NumPy Arrays are better than Python List - Comparison with examples