Matrix Multiplication not working: "You have: '(np.array(MX),MX)'"

641 views
Skip to first unread message

Tomas Santos

unread,
May 7, 2020, 4:11:39 PM5/7/20
to CasADi
Hello. 

I'm confused about how to matrix mutiply with numpy arrays. It seems as though sometimes it works and other times it does not. 

Here is an example where one matrix C is able to matrix multiply another opti.variable(m,n) matrix, however a different numpy matrix R cannot matrix multiply properly:


How can I get around this error? Previously I broke apart the matrix multiplication into scalar and vector multiplication and summation but this matrix is to large to make that a reasonable work around. 

Thank you very much for any help!



Joris Gillis

unread,
May 7, 2020, 4:21:30 PM5/7/20
to CasADi
Dear Tomas,

Ultimately, multiplication requires two MX objects.
Numeric numpy arrays will get automatically cast into MX when needed.
Object numpy arrays containing symbols will not be automatically cast.

You can use CasADi's vertcat/horzcat/blockcat here for Rot:
Rot = lambda theta : casadi.blockcat([
  [casadi.cos(theta), -casadi.sin(theta)],
  [casadi.sin(theta), casadi.cos(theta)],
])

Best regards,
    Joris

Tomas Santos

unread,
May 7, 2020, 5:59:21 PM5/7/20
to CasADi
Thanks for the quick reply. this worked perfectly. 
Reply all
Reply to author
Forward
0 new messages