Minimum Distance Algorithm using GDAL and Python
By : user3038794
Date : March 29 2020, 07:55 AM
around this issue You should definitely be using NumPy. I work with some pretty large raster datasets and NumPy burns through them. On my machine, with the code below there's no noticeable delay for a 1000 x 1000 array. An explanation of how this works follows the code. code :
import numpy as np
from scipy.spatial.distance import cdist
# some starter data
dim = (1000,1000)
values = np.random.randint(0, 10, dim)
# cdist will want 'samples' as a 2d array
samples = np.array([1, 2, 3]).reshape(1, 1)
# this could be a oneliner
# 'values' must have the same number of columns as 'samples'
mins = cdist(values.reshape(1, 1), samples)
outvalues = mins.argmin(axis=1).reshape(dim)

Minimum removed nodes required to cut path from A to B algorithm in Python
By : user7427549
Date : March 29 2020, 07:55 AM
this will help Here is an answer which ignores the list of paths. It just takes a network, a source node, and a target node, and finds the minimum set of nodes within the network, not either source or target, so that removing these nodes disconnects the source from the target. If I wanted to find the minimum set of edges, I could find out how just by searching for MaxFlow mincut. Note that the Wikipedia article at http://en.wikipedia.org/wiki/Maxflow_mincut_theorem#Generalized_maxflow_mincut_theorem states that there is a generalized maxflow mincut theorem which considers vertex capacity as well as edge capacity, which is at least encouraging. Note also that edge capacities are given as Cuv, where Cuv is the maximum capacity from u to v. In the diagram they seem to be drawn as u/v. So the edge capacity in the forward direction can be different from the edge capacity in the backward direction.

Python  convert rows to columns after group by and populate zeroes for non matching rows
By : Paulina
Date : March 29 2020, 07:55 AM
wish of those help What you need to use is pivot_table from pandas. You can specify what rows and columns you need, fill_value states what do you want to do with empty values and aggfunc len counts. I'm not sure what your DataSeries looks like, but you need sth like this: code :
pd.pivot_table(data, index='user_id', columns='type', aggfunc=len, fill_value=0)

Prim's algorithm for minimum spanning trees  confusion in algorithm
By : user3828926
Date : March 29 2020, 07:55 AM
With these it helps One of the guys at MO was kind enough to answer by email. The problem was that I didn't notice that the tree nodes are added one at a time via the ExtractMin(Q) operation. Here is the reply he gave:

krukshal's algorithm or Prims Algorithm which one is better in finding minimum spanning tree?
By : y3gang
Date : March 29 2020, 07:55 AM
I hope this helps . I'll add one point in favour of Prim's algorithm I haven't seen mentioned. If you are given N points and a distance function d(x,y) for the distance between x and y, it is easy to implement Prim's algorithm using space O(N) (but time N^2). Start off with an arbitrary point A and create an array of size N1 giving you the distances from A to all other points. Pick the point, B, associated with the shortest distance, link A and B in the spanning tree and then update the distances in the array to be the minimum of the distance already noted down to that other point and the distance from B ot that other point, noting down where the shortest link is from B and where from A. Carry on.

