I have the following coordinates separated in 2 lists:
x = [1, 2, 3, 4, 5, 5]
y = [1, 2, 3, 4, 4, 5]
and I want to make a function that returns:
1 2 3 4 5
1 2 3 4 5
Every single code I try won't skip the x= 5 y= 4, help.
I have the following coordinates separated in 2 lists:
x = [1, 2, 3, 4, 5, 5]
y = [1, 2, 3, 4, 4, 5]
and I want to make a function that returns:
1 2 3 4 5
1 2 3 4 5
Every single code I try won't skip the x= 5 y= 4, help.
you can use this function to remove duplicates:
deDupe = lambda x: list(dict.fromkeys(x))
x = [1, 2, 3, 4, 5, 5]
y = [1, 2, 3, 4, 4, 5]
deDupe = lambda x: list(dict.fromkeys(x))
print(deDupe(x))
print(deDupe(y))
>>> [1, 2, 3, 4, 5]
>>> [1, 2, 3, 4, 5]
To what I believe you asked and what @Mark Meyer suggested here's the way to only make save coordinate pairs if they are the same
[(x,y) for x,y in zip(x,y) if x == y]
It sounds like the scenario of this question is we have a set of points where an unknown subset of points is colinear, and we want to identify that colinear subset.
An excellent algorithm for this problem is random sample consensus or RANSAC. For line fitting, RANSAC is like linear regression but robust to outliers.
Line fitting with RANSAC:
The scikit-learn Python library has an implementation of RANSAC, see "Robust linear model estimation using RANSAC".
I haven't publish it to pylib, if you are going to do it in my way, follow this procedure:
git clone https://github.com/Weilory/python-regression
open python-regression
folder, copy and paste regression
folder to your base level directory.
in base level directory, which contains regression
folder, create a test.py
paste in following code:
from regression.regress import linear_regression
x = [1, 2, 3, 4, 5, 5]
y = [1, 2, 3, 4, 4, 5]
expression = linear_regression(x=x, y=y)
print(expression.write)
# y = 1.0 * x + 0.0
my_formula = expression.formula
res_x = []
res_y = []
for i, d in enumerate(x):
if my_formula(d) == y[i]:
res_x.append(d)
res_y.append(y[i])
print(res_x)
print(res_y)
# [1, 2, 3, 4, 5]
# [1, 2, 3, 4, 5]
test.py
in terminal python test.py
.Make sure numpy is installed globally on your machine.