import torch as tr def op_ket(op, vect): p = tr.einsum("ij,j->i", op, vect) return p