Search

NumPy - Part1

NumPy (Numerical Python) is the fundamental package for scientific computing in Python. It provides a multidimensional arrayobject, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays,including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more.


Why we need numpy when we have list?/Why numpy is so popular?

  • Provide faster operation for Large Scale operation
  • Behind the scene optimizations written in C
  • Vectorization via broadcasting(avoiding loops)s
  • Backbone of other python scientifi c packages


Numpy dataTypes and Attributes

Main datatype of Numpy is ndarray, where ndarray represent n dimentional array.

import numpy as np
import pandas as pd #Details of pandas library will be cover in Pandas chapter.
a1 = np.array([1,2,3])
print(a1)
print("Type of the array is {}".format(type(a1)))
print("\nData type of the array is {}".format(a1.dtype))
print("\nShape of the array is {}".format(a1.shape))
print("\nSize of the array is {}".format(a1.size))
print("\nDimention of the array is {}".format(a1.ndim))
print("\n",pd.DataFrame(a1))

O/P

[1 2 3]
Type of the array is <class 'numpy.ndarray'>

Data type of the array is int64

Shape of the array is (3,)

Size of the array is 3

Dimention of the array is 1

    0
0  1
1  2
2  3