Sum of distances from a point to all other points

0 votes

I am currently using two lists. Such as:

available_points = [[2,3], [4,5], [1,2], [6,8], [5,9], [51,35]]

and

solution = [[3,5], [2,1]]

Now I want to pop a point in available_points and append it to solution for which the sum of euclidean distances from that point, to all points in the solution is the greatest.

So I want the output as:

solution = [[3,5], [2,1], [51,35]]

Jun 10 in Python by ana1504.k
• 7,870 points
25 views

1 answer to this question.

0 votes

You can use cdist -

In [1]: from scipy.spatial.distance import cdist

In [2]: max_pt=available_points[cdist(available_points, solution).sum(1).argmax()]

In [3]: np.vstack((solution, max_pt))
Out[3]: 
array([[ 3,  5],
       [ 2,  1],
       [51, 35]])
answered Jun 10 by SDeb
• 13,160 points

Related Questions In Python

0 votes
1 answer

To simulate construct of other language does Python have a ternary conditional operator?

You can index into a tuple: (falseValue, trueValue)[test] test needs ...READ MORE

answered Oct 15, 2018 in Python by findingbugs
• 4,750 points
30 views
0 votes
1 answer

Python function to find a list of all keywords

You can use the keyword module for ...READ MORE

answered Jun 17 in Python by Ayman
27 views
0 votes
1 answer
+1 vote
2 answers

View onto a numpy array?

 just index it as you normally would. ...READ MORE

answered Oct 18, 2018 in Python by roberto
50 views
0 votes
1 answer
0 votes
1 answer

Printing a large numpy array

numpy.set_printoptions(threshold='nan') READ MORE

answered Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
104 views
0 votes
1 answer

Convert floating point number to a certain precision

With Python < 3 (e.g. 2.6 [see ...READ MORE

answered Oct 18, 2018 in Python by SDeb
• 13,160 points
39 views
0 votes
1 answer

How to remove all characters before a specific character in Python?

Use re.sub. Just match all the chars ...READ MORE

answered Feb 27 in Python by SDeb
• 13,160 points
241 views