Numpy Cheat Sheet & Quick Reference
Numpy Cheat Sheet & Quick Reference
Numpy Cheat Sheet & Quick Reference
ME
Numpy
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
Inspecting Properties
Copying/sorting/reshaping
arr.resize((5,6)) Changes arr shape to 5x6 and fills new values with 0
Adding/removing Elements
Indexing/slicing/subsetting
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
np.array_equal(arr1,arr2) Returns True if the arrays have the same elements and shape
np.sqrt(arr) Square root of each element in the array
Scalar Math
np.divide(arr,4) Divide each array element by 4 (returns np.nan for division by zero)
Statistics
Top Cheatsheet
Python Cheatsheet Vim Cheatsheet
Quick Reference Quick Reference
Recent Cheatsheet