I am newer to Python (used to work in IDL and MATLAB) and am trying to get used to how Python "indexes" arrays. I am trying to initiate a 7x13 matrix and fill it in a for loop:
def func(theta2, phi2):
sph = [[[] for l in range(6)] for m in range(12)]
for l in range(0,6):
for m in range(-6,6):
sph[l,m]=np.real(np.conjugate(sph_harm(m,l,phi2,theta2))*np.sin(theta2))
return sph
f = func(np.pi/4,np.pi/4)
This results in this error: "TypeError: list indices must be integers, not tuple ". If I remove the [l,m] index on my variable "sph", I only get a 1x1 array output instead of the desired 7x13 array output.
I have also tried removing the for loops all together and combining it all into one line:
def func(theta2, phi2):
sph = [[np.real(np.conjugate(sph_harm(m,l,phi2,theta2))*np.sin(theta2)) for l in range(6)] for m in range(-6,6)]
return sph
f = func(np.pi/4,np.pi/4)
This resulted in a list of 12, 1x6 arrays which is also not what I wanted.
This is similar to this post: How to initialize a two-dimensional array in Python? but I can't seem to figure out how to correctly implement what was suggested in the responses here.
How would I go about fixing this issue?