scipy-spatial

Image and Voronoi diagram on the same figure

丶灬走出姿态 提交于 2021-02-08 07:59:25
问题 I need to plot a Voronoi tessellation on top of an existing image using scipy.spatial.Voronoi . I have imported an image as a numpy array using matplotlib.pyplot : img_file = 'my_image.png' img = plt.imread(os.path.join(data_dir, img_file)) fig = plt.figure() ax = fig.add_subplot(111) When I display the image it works ok: ax.imshow(img) my initial image Then I want to add a Voronoi graph (for some points I choose arbitrarily) on it so I do: points = np.array([[0, 0], [0, 1], [0, 2], [1, 0],

Why cdist from scipy.spatial.distance is so fast?

筅森魡賤 提交于 2020-05-31 06:12:37
问题 I wanted to create a distance proximity matrix for 10060 records/ points, where each record/point has 23 attributes using euclidean distance as metric. I wrote code using nested for loops to calculate distance between each point(leading to (n(n-1))/2) computations). It took a long time(about 8 minutes). When I used cdist it took so much lesser time( just 3 seconds !!! ). When I looked at the source code, the cdist also uses nested for loops and moreover it makes n^2 computations(which is

Why cdist from scipy.spatial.distance is so fast?

*爱你&永不变心* 提交于 2020-05-31 06:11:20
问题 I wanted to create a distance proximity matrix for 10060 records/ points, where each record/point has 23 attributes using euclidean distance as metric. I wrote code using nested for loops to calculate distance between each point(leading to (n(n-1))/2) computations). It took a long time(about 8 minutes). When I used cdist it took so much lesser time( just 3 seconds !!! ). When I looked at the source code, the cdist also uses nested for loops and moreover it makes n^2 computations(which is