Skip to content
Advertisement

Numpy matrix multiplication with scalar results in negative zeros

I have a random nxn matrix A with floating points, then I call

JavaScript

matrix nxn which has diagonal values (0 elsewhere)

JavaScript

now I want to multiply every even row with -2 so I do

JavaScript

however it returns

JavaScript

Why do the zeroes have negative sign? Does this matter at all and if so is it possible to avoid having that? Thank you

SOLUTION

As someone pointed out, the np.eye function returns float matrix by default, fixed by adding np.eye(A.shape[0],dtype=int)

Advertisement

Answer

SOLUTION

As someone pointed out, the np.eye function returns float matrix by default, fixed by adding np.eye(A.shape[0],dtype=int)

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement