Write Python. Understand every error.

Open the editor

Cheat sheets

NumPy cheat sheet

Fast arrays for numbers. Start with import numpy as np. Each example shows the code and exactly what it prints.

import numpy as np
a = np.array([1, 2, 3])
print(a * 2, a + a)
[2 4 6] [2 4 6]
Element-by-element maths
import numpy as np
print(np.arange(0, 10, 3), np.zeros(3))
[0 3 6 9] [0. 0. 0.]
Creating arrays
import numpy as np
print(np.linspace(0, 1, 3))
[0.  0.5 1. ]
Evenly spaced values
import numpy as np
a = np.arange(6).reshape(2, 3)
print(a.shape, a[1, 2])
(2, 3) 5
Shape and 2D indexing
import numpy as np
a = np.array([4, 8, 6])
print(a.mean(), a.max(), a.argmax())
6.0 8 1
Statistics
import numpy as np
a = np.array([[1, 2], [3, 4]])
print(a.sum(axis=0), a.sum(axis=1))
[4 6] [3 7]
Sums down and across
import numpy as np
a = np.array([5, 12, 8, 20])
print(a[a > 10])
[12 20]
Boolean mask
import numpy as np
a = np.array([[1, 2], [3, 4]])
print(a @ a)
[[ 7 10]
 [15 22]]
Matrix multiplication

Practise these in the Py-CRAFT editor.

Py-CRAFT cheat sheet. © 2026 Dr. Saptarshi Das (PhD, IIT Kharagpur | ME, Jadavpur University). All rights reserved.