Issue
How to obtain the matrix Hermitian for a 2D matrix in a multi dimension np.array for example F has (3, 2, 2, 2) shape, the first two dimensions represent items in a certain category, the data is a 2D matrix exists in the last two dimensions (2*2):
import numpy as np
F=np.array([[[[ 1+2j, 2-j],[1+2j, 2-j]],
[[ 0, 2+j],[0, 3-j]]],
[[[ 1+2j, 2-j],[ 1+2j, 2-j]],
[[ 0, 2+j],[ 0, 3-j]]],
[[[ 1+2j, 2-j],[ 1+2j, 2-j]],
[[ 0, 2+j],[ 0, 3-j]]]])
So the output should be the Hermitian of all 2*2 matrices while the output should has same shape as F:
F_Herm=np.array([[[[ 1-2j, 1-2j],[2+j, 2+j]],
[[ 0, 0],[2-j, 3+j]]],
[[[ 1-2j, 1-2j],[2+j, 2+j]],
[[ 0, 0],[ 2-j, 3+j]]],
[[[ 1-2j, 1-2j],[ 2+j, 2+j]],
[[ 0, 0],[2-j, 3+j]]]])
So F_Herm.shape should be equal (3, 2, 2, 2)
Solution
You could compute conjugate of transpose
# Just an example
A=(np.arange(24)+1j*np.arange(24)).reshape(3,2,2,2)
# Swap 2 tast axes (so transpose each 2D matrix A[i,j]), and conjugate
AH = np.swapaxes(-1,-2).conj()
Here
A=array([[[[ 0. -0.j, 2. -2.j],
[ 1. -1.j, 3. -3.j]],
[[ 4. -4.j, 6. -6.j],
[ 5. -5.j, 7. -7.j]]],
[[[ 8. -8.j, 10.-10.j],
[ 9. -9.j, 11.-11.j]],
[[12.-12.j, 14.-14.j],
[13.-13.j, 15.-15.j]]],
[[[16.-16.j, 18.-18.j],
[17.-17.j, 19.-19.j]],
[[20.-20.j, 22.-22.j],
[21.-21.j, 23.-23.j]]]])
and AH
array([[[[ 0. -0.j, 2. -2.j],
[ 1. -1.j, 3. -3.j]],
[[ 4. -4.j, 6. -6.j],
[ 5. -5.j, 7. -7.j]]],
[[[ 8. -8.j, 10.-10.j],
[ 9. -9.j, 11.-11.j]],
[[12.-12.j, 14.-14.j],
[13.-13.j, 15.-15.j]]],
[[[16.-16.j, 18.-18.j],
[17.-17.j, 19.-19.j]],
[[20.-20.j, 22.-22.j],
[21.-21.j, 23.-23.j]]]])
Which, I believe, is what you expected
Applied to your F (assuming of course that j=1j
)
F.swapaxes(-1,2).conj()
⇒
array([[[[1.-2.j, 1.-2.j],
[2.+1.j, 2.+1.j]],
[[0.-0.j, 0.-0.j],
[2.-1.j, 3.+1.j]]],
[[[1.-2.j, 1.-2.j],
[2.+1.j, 2.+1.j]],
[[0.-0.j, 0.-0.j],
[2.-1.j, 3.+1.j]]],
[[[1.-2.j, 1.-2.j],
[2.+1.j, 2.+1.j]],
[[0.-0.j, 0.-0.j],
[2.-1.j, 3.+1.j]]]])
Answered By - chrslg
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.