Data science

Stage 1 · Lesson 2 of 7

NumPy arrays and vectorised maths

Python for data: NumPy and pandas

is the Python library for : blocks of values of one type that you do maths on all at once. prices * 1.18 multiplies every element without a loop, which is called vectorisation and runs many times faster than a Python for loop.

Every column is a NumPy array underneath, so its rules explain later surprises: an array has one dtype (data type), missing values are (not a number) and shapes must line up when you combine arrays, which NumPy calls .

Learn creating arrays, indexing and slicing, boolean masks, and summary functions such as mean, sum and std.

Common trapthat NumPy's std divides by n by default, while pandas and most statistics divide by n minus 1, so the same data gives two different answers.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking Python Fundamentals

    Design Gurus · Beginner · $50

    Solid Python basics first: data types, collections, functions and files, the ground pandas stands on

  • CourseFree
    Kaggle Learn

    Kaggle · Beginner

    Free: the Python and Pandas courses, short lessons with exercises that run in the browser

Practise

  • Pick one dataset on a topic you care about and repeat every operation in this stage on it

Keep handy

  • The indexing, merging and reshaping pages answer most "how do I" questions

  • The absolute beginners guide, then the reference when an array does something unexpected

Also worth your time

Mark this stage as not done?