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]]


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
• 6,830 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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))
array([[ 3,  5],
       [ 2,  1],
       [51, 35]])
answered Jun 10 by SDeb
• 11,080 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
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
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
+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
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
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
• 11,080 points
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
• 11,080 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.