I would like to do nested loop in my programming. However, this code did not meet my expectation.
X=[0,1,1,1,0]
length=len(X)
for i,val in enumerate(X):
a=0
count=0
while (count<length):
a=15+a
print (a)
HWPQ=np.matrix([[1, 0, 0, 0], [0, math.cos(4*math.radians(a)),
math.sin(4*math.radians(a)), 0], [0, math.sin(4 * math.radians(a)), -
math.cos(4 * math.radians(a)), 0], [0, 0, 0, -1]])
result=HWPQ*val
print (result)
count=count +1
print ("\n")
Supposedly, in this program, I would like to update the value of a for each element using the loop. For example:
X=0 for a=0
X=1 for a=15
X=1 for a=30
X=1 for a=45
X=0 for a=60
The result should be, as I calculated it manually:
[[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]]
[[ 1. 0. 0. 0. ]
[ 0. 0.5 0.8660254 0. ]
[ 0. 0.8660254 -0.5 0. ]
[ 0. 0. 0. -1. ]]
[[ 1. 0. 0. 0. ]
[ 0. -0.5 0.8660254 0. ]
[ 0. 0.8660254 0.5 0. ]
[ 0. 0. 0. -1. ]]
[[ 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]
[ 0.00000000e+00 -1.00000000e+00 1.22464680e-16 0.00000000e+00]
[ 0.00000000e+00 1.22464680e-16 1.00000000e+00 0.00000000e+00]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.00000000e+00]]
[[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]]
Xused in this code? Seems useless?ajust a arithmetic progression, ignore any value ofXval, which is 0, so the whole matrix would be0s.Xis represented as list of bit 0 or 1.