Reputation: 287
My goal is to use the matrix defined below in Matlab in my Python code but apparently the objects don't have the same norm? Thus, I believe that I made a mistake.
Tforward = np.array(np.mat('0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274; \
0.219417649252501 0.449283757993216 0.449283757993216 0.219417649252501 -0.219417649252501 -0.449283757993216 -0.449283757993216 -0.219417649252501; \
0.569359398342846 0.402347308162278 -0.402347308162278 -0.569359398342846 -0.083506045090284 0.083506045090284 -0.083506045090284 0.083506045090284; \
-0.083506045090284 0.083506045090284 -0.083506045090284 0.083506045090284 0.569359398342846 0.402347308162278 -0.402347308162278 -0.569359398342846; \
0.707106781186547 -0.707106781186547 0 0 0 0 0 0; \
0 0 0.707106781186547 -0.707106781186547 0 0 0 0; \
0 0 0 0 0.707106781186547 -0.707106781186547 0 0; \
0 0 0 0 0 0 0.707106781186547 -0.707106781186547'))
sum(Tforward**2,2)
>>> array([3.00428749, 2.99571251, 2.99571251, 3.00428749, 3.00428749,
2.99571251, 2.99571251, 3.00428749])
Tforward = [ 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274;
0.219417649252501 0.449283757993216 0.449283757993216 0.219417649252501 -0.219417649252501 -0.449283757993216 -0.449283757993216 -0.219417649252501;
0.569359398342846 0.402347308162278 -0.402347308162278 -0.569359398342846 -0.083506045090284 0.083506045090284 -0.083506045090284 0.083506045090284;
-0.083506045090284 0.083506045090284 -0.083506045090284 0.083506045090284 0.569359398342846 0.402347308162278 -0.402347308162278 -0.569359398342846;
0.707106781186547 -0.707106781186547 0 0 0 0 0 0;
0 0 0.707106781186547 -0.707106781186547 0 0 0 0;
0 0 0 0 0.707106781186547 -0.707106781186547 0 0;
0 0 0 0 0 0 0.707106781186547 -0.707106781186547];
sum(Tforward.^2,2)
>>> ans =
1.00000
1.00000
1.00000
1.00000
1.00000
1.00000
1.00000
1.00000
Any help appreciated
Upvotes: 0
Views: 180
Reputation: 48
The difference between MATLAB Sum and Python Sum is not the same thing. If you have MATRIX A, sum(A,2) in Matlab gives you the sum from the second column. However, in Python, sum(A,2) gives you the sum from of the list but also applies the number you entered into the list.
So in MATLAB you did sum(A(:,2)) while in Python you did sum(A+2). I believe Taha is correct in the comments that you want np.sum instead
Upvotes: 1