I'm so confused with the right division in matlab.
m = [1 2 3 4 ; 5 6 7 8]
x = m/sum(m)
x =
0.2907
0.7093
I don't know how matlab gets this result, obviously x * sum(m) is not equal to m, and how to do this in python?
I'm so confused with the right division in matlab.
m = [1 2 3 4 ; 5 6 7 8]
x = m/sum(m)
x =
0.2907
0.7093
I don't know how matlab gets this result, obviously x * sum(m) is not equal to m, and how to do this in python?
Since you are not using the element-wise division, the operation you are performing equals to solving xA = B for x where A = m and B = m_sum (see mrdivide):
m = [1 2 3 4; 5 6 7 8];
m_sum = sum(m);
x = m / m_sum;
which can also be written as:
m = [1 2 3 4; 5 6 7 8];
m_sum = sum(m);
x = mrdivide(m,m_sum);
The Python equivalent, using the Numpy library, would be:
import numpy as np
m = np.matrix('1 2 3 4; 5 6 7 8')
m_sum = np.sum(m, axis=0)
x = np.dot(m, np.linalg.pinv(m_sum))