[Tutor] Need help with arrays

Patrick P. tical_1985 at hotmail.com
Wed May 4 19:30:38 CEST 2011


Hello,

I hope this is the right way to ask my question, if not, sorry to bother you. Maybe you can tell me who to ask.
Ok so here is my code
----------------------------------------------------------------------------
import numpy as np

nH = 2.2
nL = 1.7
welle = 0.5 
wurzel = (8.85*10**(-12) * 12.57*10**(-7))**0.5 * 10**6 
w = np.arange(0.50, 1.50, 0.01)

inc = 25
inc1 = np.arcsin((1/nH))*np.sin(inc)
inc2 = np.arcsin((nH/nL)*np.sin(inc1))

del0 = 2*np.pi*welle*np.cos(inc)/w
del1 = 2*np.pi*nH*(welle/nH)*np.cos(inc)/w
del2 = 2*np.pi*nL*(welle/nL)*np.cos(inc1)/w

nu1 = wurzel*nH*np.cos(inc1)                         
nu2 = wurzel*nL*np.cos(inc2)

# Matrix 1

m111 = np.cos(del1)
m121 = 1j*np.sin(del1)/nu1
m211 = 1j*nu1*np.sin(del1)
m221 = np.cos(del1)
A = np.array([[m111,m121], [m211,m221]])

# Matrix 2

m112 = np.cos(del2)
m122 = 1j*np.sin(del2)/nu2
m212 = 1j*nu2*np.sin(del2)
m222 = np.cos(del2)
B = np.array([[m112,m122], [m212,m222]])

print(np.dot(A,B))


Traceback (most recent call last):
  File "C:/Python26/helpfiletest.py", line 36, in <module>
    print(np.dot(A,B))
ValueError: objects are not aligned
-------------------------------------------------------------------------------------
I get it why theres and error message, because it's trying to multiply a 2x2x100 array with another 2x2x100 array and doesn't know how to do that.
What I actually want is 100 2x2 arrays and then mutliply them individually.
Can anyone help me with that?

Thanks a lot! Best,

Patrick
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110504/82de951b/attachment.html>


More information about the Tutor mailing list