Tsallaka zuwa abun ciki
Justice Tech School

einsum Introduction

einsum writes sums over axes in a short notation.

Example
a = np.arange(6).reshape(2, 3)
b = np.arange(6).reshape(3, 2)
print(np.einsum("ij,jk->ik", a, b))
print(np.einsum("ii", np.eye(3)))

Result

[[10 13]
 [28 40]]
3.0

Exercise

Matrix product by notation.

np.("ij,jk->ik", a, b)

Quiz Test

What is "ii" here?

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