Reputation: 1
import numpy as np
A = np.array([[2,1,-1,8],
[-3,-1,2,-11],
[-2,1,2,-3]])
B = A[1]+A[0]* (-A[1][0]/A[0][0])
print(B) #B =[ 0. 0.5 0.5 1. ]
A[1] = A[1]+A[0]* (-A[1][0]/A[0][0])
print(A[1]) #A[1] = [0 0 0 1]
How does the above situation happen, and what can I do about it?
Upvotes: 0
Views: 234
Reputation: 3547
Use dtype=float
in main array. Your array is integer by default.
import numpy as np
A = np.array([[2,1,-1,8],
[-3,-1,2,-11],
[-2,1,2,-3]], dtype=float)
B = A[1] + (A[0]*(-A[1,0]/A[0,0]))
print(B)
A[1] = A[1] + (A[0]*(-A[1,0]/A[0,0]))
print(A[1])
#Output:
#[ 0. 0.5 0.5 1. ]
#[ 0. 0.5 0.5 1. ]
Upvotes: 3