Skip to content
Justice Tech School

Array Arithmetic

Operators work element by element on arrays of the same shape: + - * / ** and %. There are no loops needed.

Example
import numpy as np
a = np.array([1, 2, 3])
b = np.array([10, 20, 30])
print(a + b, a * b)
print(b / a, a ** 2, b % 7)

Result

[11 22 33] [10 40 90]
[10. 10. 10.] [1 4 9] [3 6 2]

Exercise

Square each element.

a  2

Quiz Test

Does * multiply matrices?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.