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, 2019 in Python by ana1504.k
• 7,910 points
1,700 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, 2019 by SDeb
• 13,300 points

Related Questions In Python

+1 vote
0 answers

Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

Nov 20, 2019 in Python by Sagar
• 130 points
1,185 views
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,780 points
650 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, 2019 in Python by Ayman
11,213 views
0 votes
0 answers

Sorting arrays in NumPy by column

How can I sort a numpy array ...READ MORE

Aug 2, 2022 in Python by krishna
• 2,820 points
561 views
+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
1,032 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,300 points
666 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, 2019 in Python by SDeb
• 13,300 points
10,113 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP