0

Given m x n matrix A and n x r matrix B how to write the following formula in np.einsum notation?

f(i) = \sum_{j,k} a_ij * b_jk

What will change in np.einsum if r x p matrix C will be added?

f(i) = \sum_{j,k,l} a_ij * b_jk * c_kl
Sengiley
  • 221
  • 2
  • 7

1 Answers1

1

@Sengiley Despite you already answered yourself's question. A more general version that allows broadcasting is:

np.einsum('...ij,jk,kl->...i', a, b, c)
Shuhao Cao
  • 221
  • 1
  • 7