vendredi 14 janvier 2022

Connecting to random points in a 2d numpy array based on distance

I have a 2d numpy array and select a random coordinate position (say 10x10 array and start at position 2,3). I want to randomly connect to 40% of the other points in the 2d array effectively generating a list of tuples [(x1, y1), (x2, y2) ...] where the list is 40% of the other coordinates.
An additional constraint, however, is the goal is to reduce connection probability the farther the points are away from one another (so point 2,3 is far more likely to connect to 2,2 than 9, 8 but yet still be random so there is a chance albeit small of connecting to 9, 8).

I believe I need to create some sort of Guassian function centered on 2,3 and use this to select the points, but any Gaussian I create will generate non-integer values - requiring additional logic as well as presents problem of needing to handle x and y dimensions separately.

Currently, I am trying to use np.meshgrid with gauss = np.exp(-(dst2 / (2.0 * sigma2)))

Is there an easier way to do this or a different approach someone might recommend?




Aucun commentaire:

Enregistrer un commentaire