Introduction to Numpy Library in Python
NUMPY - Introduction

Introduction to Numpy Library in Python

Introduction

NUMPY stands for Numerical Python. Numpy is one of the libraries for the python programming language. It is used for high level mathematical calculations. It has the large collection of functions for working with the multi-dimensional arrays, matrices, linear algebra, Fourier transform, etc.

Installation of Numpy

  1. Open the command or terminal on your system.
  2. Enter the following command below.

#installation of NUMPY using PIP
pip install numpy

(OR)

#installation of NUMPY using CONDA
conda install numpy        

3. Now, NUMPY installed on your system. To verify that use the command below.

#check for version of NUMPY
numpy --version        

Tip : Use Anaconda Navigator, it comes with built-in software of JUPYTER NOTEBOOKS and pre-installed packages like Numpy, Pandas, Scipy, etc.

Comparison of Lists and Numpy

In Python lists, we can multiply the 2-dimensional matrices with the help of loops.

for (i = 0; i < rows; i++): {
  for (j = 0; j < columns; j++): {
    c[i][j] = a[i][j]*b[i][j];
  }
}        

In Numpy ndarray, we can easily multiply arrays with faster execution and simply by,

c = a * b        

How to import Numpy in your program?

It is very simple to import Numpy to our program. Follow the code below.

import numpy        

Also we can give alias name to the Numpy package.

import numpy as np        

Examples

Sample program using Numpy

import numpy as np

maths = np.array([90, 67, 98, 100, 37])
science = np.array([100, 87, 47, 89, 45])

print("Maths marks : \n", maths)
print("Science marks : \n", science)

student_marks = np.array([maths, science], dtype = int)

print("Student marks of Maths and Science : \n", student_marks)        

Output

Maths marks : 
 [ 90  67  98 100  37]
Science marks : 
 [100  87  47  89  45]
Student marks of Maths and Science : 
 [[ 90  67  98 100  37]
 [100  87  47  89  45]]        

Conclusion

Numpy is an vectorized code which provides more concise and easy to read. Let us explore the all Numpy functions on upcoming articles.

Follow on LinkedIn - Trillionaire TK

Follow on Instagram - Trillionaire TK

Visit our website - Information Technology

Learn, Code, Practice!!!

To view or add a comment, sign in

More articles by Tharunkumar S

  • Comparison Operations in Numpy Arrays

    Comparison Operations in Numpy As we already know the comparison or relational operations like less than, less than and…

  • Arithmetic Operations in Numpy Arrays

    Arithmetic Operations in Numpy As we already know the arithmetic operations like addition, subtraction, division…

  • Shape of an Array and Reshape() function

    Shape of an Numpy array In Numpy array, shape is an attribute that is used to check the dimension of an array. shape…

  • Slicing in Numpy Arrays

    What is Slicing in Numpy Array? Slice the array in a particular range of elements. In other words, Make an sub array…

  • Indexing in Numpy Arrays

    What is Indexing in Numpy Array? Access the elements in a Numpy array based on index values. Accessing the elements in…

  • Explore array(), type() and astype() functions

    What is ndarray in Numpy? "ndarray" stands for n-dimensional array. Numpy creates an object for an array in this type.

  • Journey of Machine Learning Begins

    Machine Learning Definition : The term Machine Learning was coined by Arthur Samuel in 1959, an American pioneer in the…

Others also viewed

Explore content categories