spiketools.spatial.distance.compute_distances_to_location

spiketools.spatial.distance.compute_distances_to_location(position, location)[source]

Compute distances between a sequence of positions and a specified location.

Parameters:
position1d or 2d array

Position values.

locationlist of float

The position values of the two positions to calculate distance between. Can be 1d (a single value per position) or 2d (x and y values per position).

Returns:
distances1d array

Computed distances between each position in the sequence, and the specified location.

Examples

Compute distances to location across a sequence of 1d positions:

>>> position = np.array([1., 2., 3., 4., 5.])
>>> location = [3.]
>>> compute_distances_to_location(position, location)
array([2., 1., 0., 1., 2.])

Compute distances to location across a sequence of 2d positions:

>>> position = np.array([[1, 2, 2, 3],
...                      [1, 1, 2, 3]])
>>> location = [2, 2]
>>> compute_distances_to_location(position, location)
array([1.41421356, 1.        , 0.        , 1.41421356])