Array division- translating from MATLAB to Python

前端 未结 5 895
我寻月下人不归
我寻月下人不归 2020-12-19 07:43

I have this line of code in MATLAB, written by someone else:

c=a.\'/b

I need to translate it into Python. a, b, and c are all arrays. The d

5条回答
  •  渐次进展
    2020-12-19 08:12

    In Matlab, A.' means transposing the A matrix. So mathematically, what is achieved in the code is AT/B.


    How to go about implementing matrix division in Python (or any language) (Note: Let's go over a simple division of the form A/B; for your example you would need to do AT first and then AT/B next, and it's pretty easy to do the transpose operation in Python |left-as-an-exercise :)|)

    You have a matrix equation C*B=A (You want to find C as A/B)

    RIGHT DIVISION (/) is as follows:

    C*(B*BT)=A*BT

    You then isolate C by inverting (B*BT)

    i.e.,

    C = A*BT*(B*BT)' ----- [1]

    Therefore, to implement matrix division in Python (or any language), get the following three methods.

    • Matrix multiplication
    • Matrix transpose
    • Matrix inverse

    Then apply them iteratively to achieve division as in [1].

    Only, you need to do AT/B, therefore your final operation after implementing the three basic methods should be:

    AT*BT*(B*BT)'

    Note: Don't forget the basic rules of operator precedence :)

提交回复
热议问题