Don't let the Lockdown slow you Down - Enroll Now and Get 3 Course at 24,999/- Only. Explore Now!

General

How to Install NumPy in Python

How To Install NumPy in Python?

How To Install NumPy in Python?

Python is recognized as a strong and universal programming language due to its ample set of libraries. It is an open-source language and widely used across the globe. NumPy is one such library that is an integral part of Python programming.

Introduction

As we all know, Python packages make it a unique programming language. Apart from the inbuilt packages, there are too many external packages written and attached to Python. You can install these packages based on your requirements.

Python packages comprise scripts and directories. A module is nothing but a script that acts as a function, method, new python type, new functionality, etc. NumPy is one of the significant packages which is curated for simplifying the process of Python array computation.

Here, we shall discuss in detail about installing the latest version of Python which is Python 3, installing NumPy, Matplotlib, and SciPy on Windows Operating System, NumPy installation on Mac, Fedora, and Ubuntu operating systems.

Types of Operating Systems

Python packages are always installed using pip which means Package Installer for Python. Pip will be automatically installed when you install Python. Python Package Index will show you the package details based on which you can decide the packages which you want to download depending on your requirements.

What is Numpy?

Numpy – Numeric Python or Numerical Python

For scientific computing in Python, we use numpy library. It provides a multidimensional array of objects. It performs a fast operation on arrays, such as logical calculations, mathematical calculations, reshaping arrays, sorting, basic linear algebra, basic statistical operations, random value simulation and much more.

Why is Numpy fast?

Numpy is fast because it is been mostly written on C language. C language is a low-level language that makes Numpy very fast.

In python, you need not specify a variable datatype because whenever you assign a value to variable python checks the data type of the particular variable. This check of variable data types makes python slower though Python is been written in C language.

How to Install NumPy

NumPy can be installed on various operating systems like Windows, Mac, Ubuntu, Fedora, etc. Here, we will see the two standard OS such as Windows and Mac.

NumPy Installation on Windows

We must begin by installing the latest version of Python which is Python 3. However, you can visit python.org and download your required version. Visit python.org/downloads/ and download the installer. By default, you will get 32 bits installer for Windows OS. You can also go for 64 bits installer by visiting Looking for a specific release?

Let’s begin the installation. Please opt Customize installation and also tick the checkbox for all optional features in the next screen. When you arrive at the screen for Advanced Options, tick the checkbox for the following items:

  • Install for all users
  • Precompile standard library
  • Add Python to environment variables
  • Create shortcuts for installed applications
  • Associate files with Python (requires the py launcher)

You can also tick other options based on your requirements. The screen will look like the below image:

Tick Other Options Based on Your Requirements

 

Moving further, press on install to finish the installation process. Depending on your computer speed, within a few minutes, you should be done with the installation process. Do not forget to click on the Disable path length limit on the last screen of the installer. The screen will look like the below image:

Verify if Python was Successfully Installed or Not

You can verify if Python was successfully installed or not by opening a command prompt. Just press and hold the key Shift and now right-click the mouse anywhere on the desktop. Next, open a command window. Type Python in the command window and click enter. You will see the screen similar to the below image:

Successfully Installed Python

You have successfully installed Python. You can exit this screen now. Just type quit() and click enter.

Now let’s see how to install NumPyMatplotlib, and SciPy. Open the cmd window and use the following set of commands:

Python-m pip install  numpy

Python-m pip install  scipy

Python-m pip install  matplot

After typing each command from the above, you will see a message ‘Successfully installed’. You can check the version of SciPy which is installed by launching Python through cmd window. Once you do this action the screen will appear like the below image:

Check the Version of Scipy

NumPy Installation on Mac

Now, let’s try NumPy installation on a Mac OS. It is always suggestible to install it on Python 3 itself. Use the pip3 command in order to install NumPy. The usage of pip3 command is to specify your system that you are working on a Python 3 version. The below image helps you in the installation process:

NumPy Installation on Mac Procedure

NumPy Installation on Ubuntu

In case of Ubuntu, you will notice that Python is already installed but pip isn’t. If you wish to have a complete package, you must download Python from python.org on Ubuntu with the help of apt install command. Instead, you can also install only pip on Ubuntu by opening a terminal and stalling pip3 and pip with the help of apt install command. The below image shows the apt command:

apt install command

Now, when you have pip, use the same commands to install NumPy:

Commands to Install NumPy

NumPy Installation on Fedora

Python is already installed in Fedora OS quite similar to Ubuntu. Now, you just have to use pip command in order to proceed with the NumPy installation. However, do not forget to notice the difference in usage of pip command in Fedora OS for Python3.

Fedora od for python3

How to import Numpy?

Now that we have installed Numpy, we shall get to know how to work with Numpy. To use Numpy package, one has to first import the package to use the functionalities of Numpy.

We can import the package by just calling its name with import keyword,

import Numpy

You can use submodules of Numpy by calling Numpy followed by dot(.)

numpy.array()

numpy.sum()

Every time you want to use submodules of Numpy, you have to refer to the parent module name( Numpy). So we can assign an alias name to Numpy, after assigning an alias name Numpy can be called with that assigned alias name. The alias name can be assigned as per user’s wish but still, it is good practice to assign alias np which is used by coders to refer Numpy.

import numpy as np

Hereafter, you can call Numpy using its alias name np

np.array()

np.sum()

Working with Numpy

We have imported Numpy, now let us start coding using Numpy. Initially, we have seen Numpy is fast, let us write a code to check that.

Start Coding using Numpy

I have used jupyter Notebook to write my codes. To write our python codes, we need an IDE(Integrated Development Environment), I have used Jupyter Notebook.

Firstly, I have imported the required packages, time is one of the packages/libraries available in python. To check the time taken by Numpy and the normal list(a data type in python), we are using a time package. The output shown clearly shows that Numpy has taken very little time to complete when compared to the normal list.

Related Blogs:

  1. Brief Overview of Python Language
  2. Python Career opportunities
  3. Python Break Continue
  4. Python Control Flow
  5. Python Data Types
  6. Python Dictionary
  7. Python Exception Handling
  8.  Python File
  9. Python Functions
  10. Python Substring
  11. Hash Table and Hash Map in Python

 

Scroll Up
Besant Technologies WhatsApp