DEV Community

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

Posted on • Edited on

1

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

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 👀

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay