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 1,560 views

## 1 answer to this question.

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
• 13,300 points

## Write a program to get a string from a given string where all the occurrences of its first char have been changed to '\$' , except the first char itself?

You can use the code below: lis = ...READ MORE

+1 vote

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

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

## Python function to find a list of all keywords

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

## I am not able to install numba-special in linux ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I am trying to install numba-special after ...READ MORE

## Sorting arrays in NumPy by column

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

+1 vote

## View onto a numpy array?

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

## Dimension in python numpy

Use the .shape to print the dimensions ...READ MORE