How to import numy in python
How to Install NumPy in Python
Python is a vast ocean of libraries, modules, and different functions. It has a solution for almost everything. Using Python, we can simplify even a complex problem with the help of help of libraries and modules; one of such libraries is NumPy.
If you are from C/ C++ background, you must be aware of arrays. In Python, we don't have arrays, and in place of them, we have lists. The drawback here is that lists are slower than arrays.
To solve this drawback, we have a library – NumPy. It stands for numerical Python. NumPy provides an array object called ndarray. These arrays are about 50 times faster than the lists that we use in Python. The library also provides different functions to work with these arrays.
Simply, it is a library used for multidimensional array processing. It provides N-dimensional array object and also sophisticated functions to work with these arrays.
To use it, we need to install this library. In this article, we will see the installation process.
Requirement: Python and PIP versions must be already installed in the system.
Steps to install NumPy
1. Check if Python and pip are installed by opening the cmd via search and typing the command:
Python --version
If Python is already installed in the system, it shows the version number; if not, it shows an error:
If it is not installed:
Then, you need to install Python first.
The other requirement is PIP – It is a package management system that manages the packages and modules installed in Python. We checked if Python is installed or not; now we need to check PIP.
pip –version
If it is not installed, install it
If both Python and PIP are present in your system, it is now time to install the NumPy library; Follow the below steps:
- Open cmd from the start menu
- Type the command
pip install numpy
All the library packages, data, and sub-packages will be installed one after the other.
Please wait for the successful message, and that is it.
To confirm if the installation process is successful, follow the below steps:
- Open cmd
- Type Python
- Now, you enter the interactive mode
- Now, type the commands:
import numpy
numpy.__version
If the process is successful, it will display the version number.
In Anaconda IDE
If you are using anaconda:
- Open the anaconda prompt from the search
- Type the command:
conda install –c anaconda numpy
Best practices while installing:
- Rather than using the base environment, use another environment for installation. For that, use this command:
conda create –n my-env
conda activate my-env
- To use conda-forge, type the command:
conda config –env –add channels conda-forge
Conda forge is an open-source anaconda community. It packs up different packages in one spot. We can install them online on the official website too.
After installation, to check if the process is successful:
- Open the anaconda prompt from the search menu
- Type Python
- Now, you enter the interactive mode
- Now, type the commands:
import numpy
numpy.__version
If the process is successful, it will display the version number.