Search code examples
python-3.xpython-requestsmatrix-multiplication

multiplying a matrix with identity matrix results in some matrix elements to be zero


I have a matrix m which has some float numbers. When I multiply it with the Identity matrix, some elements if the resulting matrix becomes zero. Actually, there should be no change in the matrix. Can anyone help me?

1

In the above image, there is no 0.013 in the matrix.


Solution

  • The * operator in numpy corresponds to element-wise product of two arrays. Use the @ operator for matrix multiplication.

    m@I