What is NumPy Library and installation

Python Numpy is an open-source package for scientific computing. It is used for working with numerical data in Python and also as Numeric Python.NumPy library is used widely in Pandas, SciPy, Matplotlib, sci-kit-learn, scikit-image, and many other data sciences and scientific Python packages. It is a Python package that provides support for:

  • NumPy array is a multidimensional array object.
  • Masked arrays and matrices.
  • Functions for fast operations on arrays.
  • Coverage for operations in mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms basic linear algebra, basic statistical operations, random simulation, and much more.
  • NumPy fully supports OOPS, ndarray is a class. This class contains methods and attributes. This provides the flexibility to the NumPy library to support several operations on n-Dimensional arrays.
  • In NumPy all operations behave with implicit element-by-element fashion, i.e., they broadcast. So operations on one element can broadcast to other elements of the array which makes the operations faster.

Features of NumPy library are

  • NumPy arrays have a fixed size at the time of creation, if we want any change at runtime then ndarray creates a new array and deletes the old one.
  • The elements in a NumPy array must be of the same data type and memory size. But if we have objects then it allows different size elements.
  • ndarray is designed with Vectorization, which means the absence of explicit looping and indexing etc at the time of operations. This helps in faster code execution, easy code management, fewer bugs.

How to Install of NumPy library on Window

The complete instruction of installing the NumPy library on your OS detail here

  • Download & Install the Python executable binaries on your Windows system from Python.org.
  • Run the Python executable installer to complete the installation.
  • Install pip on your machine.
  • use the below pip commands to install NumPy Library on your PC.
  • Open the command prompt and use the command “pip install numpy”
pip install numpy

How to import NumPy Library

To access NumPy and its features we need to import numpy in our code by using below we can import numpy. We have used shortened import names as np for better readability of code using NumPy.

import numpy as np

What is ndarray – NumPy array

The core component of the NumPy library is the ndarray. ndarray object provides the implementation of n-dimensional arrays of homogeneous data types. ndarray is designed and implemented to accomplish high performance. ndarray has several important differences when it’s compared with the standard Python sequences like lists and dictionaries etc.

NumPy arrays are optimized for advanced mathematical and scientific operations with large data sets. These optimizations in ndarray make it superior to Python’s built-in sequences.

How to create numpy arrray

The Python NumPy module is mainly used in arrays manipulation, array objects in Numpy known as ndarray. The NumPy library array() method to create an array ndarray from sequences like list, lists of the list, tuple, or array_like object.

1. Create 1 Dimensional NumPy array from List

In this example, we are passing a list of sequence types to create a 1D NumPy array.

import numpy as np
array_one = np.array([14,15,16,17,18,23])

print("one dimesnional NumPy array from list :",array_one)


one dimesnional NumPy array from list : [14 15 16 17 18 23]

2. Create 1D NumPy Array from tuple

In this code example, we are passing a tuple to np. array() method to create a 1D NumPy array from the tuple.

import numpy as np

tuple = (14,56,16,21,78,25)

np_array  = np.array(tuple)
print("Shape: ", np_array.shape)

print("NumPy 1D array from Python Tuple :\n",np_array)


Shape:  (6,)
NumPy 1D array from Python Tuple :
 [14 56 16 21 78 25]