I have a random nxn matrix A
with floating points, then I call
JavaScript
x
2
1
X = np.eye(A.shape[0])
2
matrix nxn which has diagonal values (0 elsewhere)
JavaScript
1
5
1
1 0 0 0
2
0 1 0 0
3
0 0 1 0
4
0 0 0 1
5
now I want to multiply every even row with -2 so I do
JavaScript
1
2
1
X[0::2] *= -2
2
however it returns
JavaScript
1
5
1
2 0 0 0
2
-0 -2 -0 -0
3
0 0 2 0
4
-0 -0 -0 -2
5
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)