WeiNote

yyrcd

web

TA

NOV

06

NOV

03

einsum

  1. python - Understanding NumPy's einsum - Stack Overflow
  2. A basic introduction to NumPy's einsum – ajcr – Haphazard investigations
  3. 能「看到」的张量运算:​因子图可视化
A = np.array([0, 1, 2])
B = np.array([[ 0,  1,  2,  3],
              [ 4,  5,  6,  7],
              [ 8,  9, 10, 11]])

(np.expand_dims(A, 1) * B).sum(axis=1)  # array([ 0, 22, 76])
np.einsum('i,ij->ij', A, B)  # array([[ 0,  0,  0,  0],
                             #        [ 4,  5,  6,  7],
                             #        [16, 18, 20, 22]])

np.einsum('i,ij->i', A, B)   # array([ 0, 22, 76])

np.einsum('i,ij->', A, B)    # 98

Here is what happens next:

  • A has one axis; we've labelled it i. And B has two axes; we've labelled axis 0 as i and axis 1 as j.

  • By repeating the label i in both input arrays, we are telling einsum that these two axes should be multiplied together.

  • Notice that j does not appear as a label in our desired output. By omitting the label, we're telling einsum to sum along this axis.

SEP

30

  • (AB) = BA

  • Hermitian
    Hermitian matrix (or self-adjoint matrix) is a complex square matrix that is equal to its own conjugate transpose

  • Commutator
    • If two operators commute
      The observables A and B can be measured simultaneously with infinite precision
    • If the operators do not commute
      They can't be prepared simultaneously to arbitrary precision, and there is an uncertainty relation between the observables