I have two functions and an array which contains X and Y coordinates. One of the function calculates slope and another function is intended to determine collinearity. There is some weird behavior going on. I apologize if I am missing something clearly obvious.
def slope(list, a, b):
slope = 0
#vertical line
if(list[a][0] == list[b][0]):
slope = float("inf")
if(list[a][1] == list[b][1]):
slope = float("-inf")
else:
slope = (list[b][1] - list[a][1])/(list[b][0] - list[a][0])
return slope
def FastCollinearPoint(list):
slope_array = list
#print(slope_array[0][1])
for i in range(len(list)):
ss = slope(list, 0 ,i)
print(ss)
#slope_array[i][0] = ss
current output -
-inf
2.0
0.5
4.5
2.0
1.0
1.2142857142857142
2.5
:
:
If I uncomment the line slope_array[i][0] = ss, the output becomes -
-inf
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
0.0
-0.0
-0.0
-0.0
0.0
:
:
I don't understand how the value of the previously calculated variable is changing when I assign it to a new variable. Here is the complete code - https://pastebin.com/SxYjs0jY
Here is the input file mentioned in the link - https://pastebin.com/EMHBWxqT
P.S. - I sincerely apologize in advance if this is a dumb question or something stupid has been done by me.