What is NumPy?
NumPy supports large n-dimensional arrays (also known as ndarrays) and matrices. It comes preloaded with numerous handy mathematical functions for these n-dimensional arrays.
Where do we use NumPy?
NumPy is capable of driving all machine learning and deep learning models. The simplest units of these models are stored as NumPy arrays.
Other prominent uses of NumPy include:
- Pandas DataFrames are converted internally into NumPy arrays for a wide variety of tasks.
- Graphing libraries such as Matplotlib also implicitly or explicitly take NumPy ndarrays to create visualizations.
NumPy offers faster operations in comparison with Python lists. Many NumPy operations are internally implemented in C, thereby reducing the time spent on factors like Python loops.
How can you get started with NumPy?
1. If you use pip, then type the following command to install NumPy as part of your Python environment:
python -m pip install numpy
2. If you use Anaconda, then you don’t have to install anything since it comes pre-installed with the latest version of NumPy.
3. Once installed, import NumPy in your Python shell with the following command:
import numpy as np
4. After the import, you can start doing operations.
Creating NumPy arrays
Run the following command to create two NumPy arrays:
arr_1 = np.array([1,2,3]) arr_2 = np.array([2,2,2,])
Mathematical functions in NumPy
To take the dot product of two NumPy arrays, use NumPy’s built-in dot function.
To add two NumPy arrays, use the add function.
To learn more about the various functions that NumPy offers, you can go through the NumPy User Guide by SciPy.org.
Think we're missing something? 🧐 Help us update this article by sending us your suggestions here. 🙏