DEV Community

Cover image for Introduction to Numpy
Zaynul Abedin Miah
Zaynul Abedin Miah

Posted on • Updated on

Introduction to Numpy

Numpy is a general-purpose array-processing package. It's a linear algebra of python. It's important for data science it's because all py data ecosystem rely on numpy as their building blocks. Numpy is incredibly fast and has bindings to see library.

Arrays
Array in Numpy is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In Numpy, number of dimensions of the array is called rank of the array.

Image description

Image description
Methods in Numpy

  • array()
  • arange()
  • zeros()
  • argmin()
  • argmin()
  • random.rand() (from random library)
  • amax()
  • amin()
  • asmatrix()
  • arr.shape
  • arr.arrange()
  • arr.dtype
  • randint() (from random library)
  • linspace()
  • ones()
  • eye()
  • reshape()

These are just some common ones there are more methods.

Indexing and slicing
One-Dimensional NumPy Array Elements with Indexing

Image description
Two-Dimensional NumPy Array Elements with Indexing

Image description

Slicing and Striding NumPy Arrays

Image description

Integer Array Indexing in NumPy to Access Multiple Elements

Image description

Boolean Indexing in NumPy Arrays for Conditional Slicing
Image description

Array Operations
You can use addition, subtract, multiply, divide an array by an array. But when dividing look out if the array has zero inside it or when dividing the whole array by one if the array contains zero it will run but won't give you an error but will give you a warning.

You can also use trigonometric functions, log and other operations. Do look at this website if the functions you are trying to use are available at NumPy library or not.
https://docs.scipy.org/doc/numpy-1.15.1/reference/ufuncs.html

Top comments (0)