Let's say I have this calculation to do:
What is the best way to do it in Python? I come from a Matlab background and Matrices in Matlab are so easy to handle. I have tried with numpy but it gives me this error message:
ValueError: setting an array element with a sequence.
Here is a snippet of my code:
for i in Xh:
for u in Yh:
E= (np.array([(C,D),(E,F)]) * np.array([(i),(u)]) ) + np.array([Cx,Cy])
Please note that Xh
and Yh
are lists already calculated, this is why I am using the for loops (I know I can make it faster with list comprehensions).
Edit: This is a good solution that I got from this topic, and that works perfectly. For anyone who is facing the same problem, it could help.
a = np.matrix([[1,2],[3,4]])
v1 = np.matrix([[0],[1]])
v2 = np.matrix([[1],[1]])
res = np.dot(a,v1)+v2 # python version <= 3.5
res = a@v1+v2 # python version > 3.5 with the new dot operator @