Questions tagged [scipy-spatial]
103 questions
1
vote
1 answer
Error in importing module of python library scipy
I am working on clustering in python. The package I want to import is
from scipy.spatial.distance import dist
but this is showing the following error.
ImportError: cannot import name 'dist' from 'scipy.spatial.distance'…

majid bhatti
- 83
- 12
1
vote
1 answer
Do you need to normalize your data before using scipy.spatial.distance.cosine() in python?
I have two datasets D1 and D2. Each data set has n features (columns) and the feature values have different scales. I need to find the cosine distance between each relevant pair of samples in D1 and D2 to quantify how much D1 and D2 are similar. Do…

khemedi
- 774
- 3
- 9
- 19
1
vote
1 answer
Improve performance of Voronoi volume estimation
I need to estimate the volumes associated with a set of Voronoi cells in a multi-dimensional space. From this question Volume of Voronoi cell (python) I tested this answer and it works, but it is really slow.
In the code below, obtaining the volumes…

Gabriel
- 40,504
- 73
- 230
- 404
1
vote
1 answer
In python is there something similar to scipy.spatial.distance.cdist but for displacements (fast)?
I've been working on a research code for a few weeks and have been trying to speed it up by using cdist rather than a multi-level for loop to calculate the distances between every point in a matrix.
What I want:
from scipy.spatial.distance…

Zeke Piskulich
- 13
- 4
1
vote
0 answers
Scipy Voronoi 3D geometry return each bounding face
So Scipy Voronoi algorithm works relatively well for my application. In the 3D situation, a given polygon is specified by its faces. However, the Voronoi algorithm doesn't generate data in hierarchical order going from vertices to edges, then to…

DrKeith
- 59
- 5
1
vote
1 answer
Matplotlib Polygon gets fill outside of polygon
I have a collection of polygons, created with scipy.spatial.Voronoi (specifically, a subset of the Voronoi regions), which I'd like to plot with matplotlib. However, it seems like there are some constraints on the vertex order of the matplotlib…

arnsholt
- 851
- 7
- 17
1
vote
2 answers
Python: scipy/numpy all pairs computation between two 1-D vectors
I have two lists l1 and l2 containing integers that may be of different lengths, and I want to perform a computation between every possible pairing between these two vectors.
Specifically, I'm checking the Hamming distance between each pair and if…

Filip Allberg
- 3,941
- 3
- 20
- 37
1
vote
0 answers
Speeding up nearest Neighbor with scipy.spatial.cKDTree
I'm trying to optimize my nearest neighbor distance code that I need to calculate for many iterations of the same dataset
I am calculating the nearest neighbor distance for the points in dataset A, to the points in dataset B. Both datasets contain ~…

Mike Azatov
- 402
- 6
- 22
1
vote
0 answers
facing with an error: "RuntimeWarning: invalid value encountered in sqrt" while calculating distance-matrix
I have generated a matrix randomly with:mtx=numpy.random.rand(100,3)
then I tried to reduce the dimension of matrix to 2 using:
from sklearn.manifold import TSNE
newMTX=TSNE(2,method='barnes_hut')
After that I wanted to calculate the…

morteza rahimi
- 23
- 3
1
vote
2 answers
Memory efficient mean pairwise distance
I am aware of the scipy.spatial.distance.pdist function and how to compute the mean from the resulting matrix/ndarray.
>>> x = np.random.rand(10000, 2)
>>> y = pdist(x, metric='euclidean')
>>> y.mean()
0.5214255824176626
In the example above y gets…

Querenker
- 2,242
- 1
- 18
- 29
1
vote
1 answer
Issue : Correlation always gives nan values
I am a newbie in python and trying to execute the below code :
from scipy.spatial.distance import correlation
u1=np.array([10])
u2=np.array([20])
correlation(u1,u2)
But I am getting nan, why?
RuntimeWarning: invalid value encountered in…

KMittal
- 602
- 1
- 7
- 21
1
vote
1 answer
How to get coordinates of border meeting points from scipy.spatial.Voronoi
I'm using scipy.spatial.Voronoi to calculating Voronoi diagram:
import numpy as np
from scipy.spatial import Voronoi
points = np.array([[51.129378, 17.02925 ],
[51.086225, 17.012689],
[50.913433, 15.765608],
…

Damian Melniczuk
- 393
- 6
- 18
1
vote
1 answer
Error while importing scipy.spatial.distance in python
While I am running this code in ubuntu 14.04, I want to calculate the cosine distance of an array with scipy.spatial.distance. But it is throwing me an error in importing scipy.spatial.distance.
import numpy as np
import scipy
from…

M. ahmed
- 53
- 2
- 11
1
vote
1 answer
Finding minimual spatial distance
The task is to find such a dot with a (x,0) coordinates, that the distance from it to the most distant point from the original set (distance is Euclidean) is minimal.
My idea is to find the minimum of the function that finds an euclidean distance…

nutcracker
- 101
- 1
- 9
1
vote
2 answers
How do I create empty lists in a numpy Boolean array that identifies empty lists?
I am trying to create a Boolean array that identifies empty lists in an array. I did the following code:
import numpy as np
from scipy.spatial import cKDTree
rand_points = np.random.rand(5,3)
other_points = np.zeros((5,3))
for i in range(3):
…

Ben Oppenheimer
- 27
- 2