Ok guys, I might be very tired here, but I can't figure out why this matrix multiplication by a scalar gives the following result (python)

Matrix named 'dx'
[ 1.6, 3.6, 0.4, 14.4, 25.6],
[10. , 10. , 0.4, 14.4, 3.6],
[ 0.4, 0. , 0. , 1.6, 10. ],
[ 6.4, 0. , 3.6, 1.6, 0.4],
[14.4, 0. , 25.6, 0.4, 6.4]

10 * dx, in python, gives
[ -40., -60., -20., -120., -160.],
[-100., -100., -20., -120., -60.],
[ -20., 0., 0., -40., -100.],
[ -80., 0., -60., -40., -20.],
[-120., 0., -160., -20., -80.]

From what I understand, each member should be multiplicated by 10, but it's clearly not the case.

I'm using Python 3.6 & numpy

What Am I missing ? Link to matrix multiplication by scalar , pretty basic stuff : http://www.purplemath.com/modules/mtrxmult.htm

Thanks !

closed as off-topic by Aditya, Toros91, Icyblade, Stephen Rauch, Stereo Mar 18 at 19:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about data science, within the scope defined in the help center." – Aditya, Toros91, Icyblade, Stephen Rauch, Stereo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I suggest show the complete code to replicate this, it cannot be very long. Very likely you have some other function or effect occurring and you are missing it. – Neil Slater Mar 14 at 21:38
  • There is some other function affecting the final value. – Ankit Seth Mar 15 at 5:24
up vote 6 down vote accepted

It works for me.

>>> import numpy as np
>>> dx = np.matrix([[ 1.6, 3.6, 0.4, 14.4, 25.6],
... [10. , 10. , 0.4, 14.4, 3.6],
... [ 0.4, 0. , 0. , 1.6, 10. ],
... [ 6.4, 0. , 3.6, 1.6, 0.4],
... [14.4, 0. , 25.6, 0.4, 6.4]])
>>> 10 * dx
matrix([[  16.,   36.,    4.,  144.,  256.],
        [ 100.,  100.,    4.,  144.,   36.],
        [   4.,    0.,    0.,   16.,  100.],
        [  64.,    0.,   36.,   16.,    4.],
        [ 144.,    0.,  256.,    4.,   64.]])

You might want to check if you have redefined dx before the multiplication.

Not the answer you're looking for? Browse other questions tagged or ask your own question.