Audiences
This tutorial has been prepared for those who want to learn about the basics of NumPy. It is specifically useful for algorithm developers. After completing this tutorial, you will find yourself at a moderate level of expertise from where you can take yourself to higher levels.
Prerequisites of Numpy
You should have a basic understanding of computer programming. Basic understanding of Python and Math.
What is Numpy?
NumPy is a Python library used for working with arrays. It also has functions for working in domain of linear algebra, fourier transform, and matrices. NumPy was created in 2005 by Travis Oliphant. It is an open source project and you can use it freely. NumPy stands for Numerical Python.
Why Use Numpy?
In Python we have lists that serve the purpose of arrays, but they are slow to process. NumPy aims to provide an array object that is up to 50x faster than traditional Python lists. The array object in NumPy is called ndarray
, it provides a lot of supporting functions that make working with ndarray
very easy. Arrays are very frequently used in data science, where speed and resources are very important.
Why is Numpy Faster Than Lists?
NumPy arrays are stored at one continuous place in memory unlike lists, so processes can access and manipulate them very efficiently. This behavior is called locality of reference in computer science. This is the main reason why NumPy is faster than lists. Also it is optimized to work with latest CPU architectures.
Which Language is Numpy written in?
NumPy is a Python library and is written partially in Python, but most of the parts that require fast computation are written in C or C++.
Numpy Operations
A developer can perform the following operations using Numpy :
- Mathematical and logical operations on arrays.
- Fourier transforms and routines for shape manipulation.
- Numpy has in-built functions for linear algebra and random number generation.
Installation of Numpy
If you have Python and PIP already installed on a system, then installation of NumPy is very easy.
Install it using this command
pip install numpy
Import NumPy
Once NumPy is installed, import it in your applications by adding the import
keyword:
import numpy
NumPy as np
NumPy is usually imported under the np
alias.
alias: In Python alias are an alternate name for referring to the same thing.
Create an alias with the as
keyword while importing:
import numpy as np
Now the NumPy package can be referred to as np
instead of numpy
.
![](http://genesiscube.ir/wp-content/uploads/2022/11/numpy-cheat-sheet.png)
Recommended for you:
MOST COMMENTED
Tutorial
Important Methods in Matplotlib
Machine Learning
Bias and Variance Tradeoff Machine Learning
Tutorial
Multiclass and Multilabel Classification
Machine Learning
Reinforcement Learning in Machine Learning
Deep Learning
Alexnet Architecture Code
Machine Learning
Machine Learning Models Explained