Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy find most distant elements in array

# credit to Stack Overflow user in the source link
# lower complexity, works with low dimension, convex distributed data
import numpy as np
from scipy import spatial

pts = np.random.rand(100_000, 2)
# two points which are fruthest apart will occur as vertices of the convex hull
candidates = pts[spatial.ConvexHull(pts).vertices]
# get distances between each pair of candidate points
dist_mat = spatial.distance_matrix(candidates, candidates)
# get indices of candidates that are furthest apart
i, j = np.unravel_index(dist_mat.argmax(), dist_mat.shape)
print(candidates[i], candidates[j])
Comment

PREVIOUS NEXT
Code Example
Python :: ascii julius caesar python encryption 
Python :: unique character 03 set and length comparison 
Python :: write console output in same place 
Python :: Using *args to pass the variable-length arguments to the function 
Python :: python 3.9 32 bit 
Python :: python combine images horizontally next to each other 
Python :: linkedin python test 
Python :: how to move mouse by detected face and eye using opencv 
Python :: how to add item to a list in pithon 
Python :: import variables fron another file 
Python :: how to check weight value in keras neurons 
Python :: Find element with class name in requests-html python 
Python :: Python NumPy atleast_3d Function Example 
Python :: Updating hash password in python 
Python :: how to make dinamic table in jinja python 
Python :: Python NumPy asmatrix Function Syntax 
Python :: Python NumPy dstack Function Syntax 
Python :: TemplateDoesNotExist at / 
Python :: torch mean of tensor 
Python :: find max in for scartch python 
Python :: del mutiple indexes at once 
Python :: NumPy packbits Code Packed array along axis 1 
Python :: center pyfiglet to terminal 
Python :: pandas dataframe limit rows by col value 
Python :: print python age input 
Python :: How to convert an XML file to nice pandas dataframe 
Python :: function multiply(a b) 
Python :: Example 1: How isidentifier() works? 
Python :: how to seperate the script from html template when using jQuery in flask 
Python :: Evaluate mathematical expression 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =