Numpy Cheat Sheet & Quick Reference
Numpy Cheat Sheet & Quick Reference
NumPy is the fundamental package for scientific computing with Python. This cheat sheet is a quick reference for NumPy beginners.
# Getting Started
Introduction
import numpy as np
Importing/exporting
Creating Arrays
np.arange(0,10,3) Array of values from 0 to less than 10 with step 3 (eg [0,3,6,9])
Inspecting Properties
Copying/sorting/reshaping
arr.resize((5,6)) Changes arr shape to 5x6 and fills new values with 0
Adding/removing Elements
Combining/splitting
arr[0:3] Returns the elements at indices 0,1,2 (On a 2D array: returns rows 0,1,2)
arr[:2] Returns the elements at indices 0,1 (On a 2D array: returns rows 0,1)
Vector Math
Scalar Math
np.divide(arr,4) Divide each array element by 4 (returns np.nan for division by zero)
Statistics