I have a division error with the matrix below. I want to divide the 10 x 10 matrix, with a 10 x 1 vector of the sum of the rows.
[[5731, 3, 20, 8, 12, 54, 46, 8, 39, 2],
[ 2, 6472, 47, 24, 7, 44, 7, 11, 116, 12],
[ 55, 36, 5296, 104, 84, 27, 106, 53, 183, 14],
[ 50, 49, 132, 5312, 2, 253, 36, 58, 142, 97],
[ 16, 28, 36, 9, 5381, 11, 55, 24, 85, 197],
[ 62, 45, 30, 181, 77, 4631, 117, 28, 161, 89],
[ 33, 23, 37, 1, 43, 92, 5642, 4, 42, 1],
[ 20, 20, 74, 23, 55, 14, 4, 5788, 18, 249],
[ 52, 155, 74, 143, 14, 170, 50, 30, 5036, 127],
[ 43, 32, 32, 85, 174, 40, 2, 197, 79, 5265]]
The sum_vector of the rows:
[[5923],
[6742],
[5958],
[6131],
[5842],
[5421],
[5918],
[6265],
[5851],
[5949]]
However, I keep getting this matrix below when the division occurs matrix / sum_vector
[[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]]
I've tried this post and this post, but still getting all zeros.
I can divide the matrix by a scalar and it will return correctly. However it is something with my division that is returning all zeros.
I've also tried np.divide(matrix, sum_vector.reshape((10,1))) and matrix / matrix.sum(axis=1)[:,None].
I feel like I'm missing something with the dimensions of the matrices, but I can't figure it out.
Suggestions?
/is integer division for integers. You can usematrix.astype(np.float)/sum_vectorto get floating point results.