NumPy Tutorial menu

NumPy Tutorial

NumPy is a Python library for working with numbers in large groups, called arrays. Its name is short for Numerical Python.

Almost every data science and AI tool in Python is built on top of NumPy, including Pandas, SciPy, scikit-learn and many deep learning libraries.

Why Learn NumPy?

  • NumPy arrays are much faster than normal Python lists for maths, often 10 to 100 times
  • You can do a calculation on a whole array in one line, without writing a loop
  • It has ready-made functions for statistics, random numbers and linear algebra
  • It is the foundation for Pandas, Matplotlib and machine learning

A First Example

Imagine the prices of five items in a Karachi shop. Add a 10% increase to all of them at once:

Example

python
import numpy as np

prices = np.array([120, 450, 80, 1500, 300])
new_prices = prices * 1.10
print(new_prices)
Output
[ 132.  495.   88. 1650.  330.]

With a list you would need a loop. With NumPy, one line does it.

What You Will Learn

  • Installing and importing NumPy
  • Creating arrays of one, two or more dimensions
  • Indexing and slicing arrays
  • Data types, shape and reshaping
  • Maths on arrays, broadcasting and universal functions
  • Statistics, random numbers, sorting and filtering

You should know basic Python first: variables, lists, loops and functions. If not, start with our Python tutorial.

Exercise

What is the usual short name used when importing NumPy?

What to Learn After NumPy

Next, learn Pandas to work with tables of data like Excel sheets, and SciPy for statistics, optimization and scientific tools.

Want to learn with a teacher? The Workownix Python Programming course covers Python, NumPy and Pandas with practical projects, online or at our institute in Orangi Town, Karachi.

Learn NumPy with a teacher

Join the Python Programming course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp