python - How to use out parameter in numpy.argmin to retrieve minimum indices? -


according numpy.argmin documentation, third parameter out should provide indices (as understand):

out : array, optional if provided, result inserted array. should of appropriate shape , type.

but having trouble using collect indices of minimum twenty of large numpy.ndarray (dist in following snippet).

# here using smaller size arrays, hold rgbs of images     = np.random.normal(size=(10,3)) b = np.random.normal(size=(1,3)) # compute distances between 2 arrays dist = scipy.spatial.distance.cdist(a,b) index_of_minimum = np.argmin(dist) # create array hold indices: same shape , same datatype indices = np.array(dist.shape, dtype=np.float64) np.argmin(dist, axis=0, out=indices) 

but following error:

valueerror: output array not match result of np.argmin.

there similar questions asked before requirement different. first, possible collect indices of minimum using out parameter? if how can that?

two problems: first there type in line 6. should say

dist 

rather than

list 

this not influence last part though.

the second problem shape of indices. works me with

indices = np.zeros(dist[0].shape, dtype=np.int64) 

for index array need integer type. due axis=0 expected shape has 1 less dimension original dist array. explicitly taking out 0-axis in initiation of indices


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -