After getting my solution accepted, I looked at the suggested answer, and it looked dubious to me:
eigenvectors = np.linalg.eig(B)[1]
eigen_projectors = np.array([np.outer(vector,np.conj(vector)) for vector in eigenvectors])
return eigen_projectors
I think this doesn’t do what it’s actually supposed to do. For convenience, the task is to populate eigen_projectors
with projectors to the respective eigenspaces determined by the observable B
. However, I have noticed the following:
- First,
B
should be assumed to only be Hermitian, and sonp.linalg.eigh
should be used. - The other issue is that
for v in a
iterates through the row vectors of a matrix, but the NumPy API docs note that the eigenvectors are the column vectors. Instead, the more cluttered...np.conj(eigenvectors[:,i])) for i in range(eigenvectors.shape[1])
should be used;eigenvectors.shape[1]
can be replaced withlen(eigenvectors)
at the cost of semantic transparency.- The row vectors will still form projectors under
np.outer
, and even an orthonormal basis, but they are not themselves related to the eigenspaces (they encode the linear combination of the column basis vectors that recovers the original matrixB
).
- The row vectors will still form projectors under