python - Get the indices of N highest values in an ndarray -


Considering 100x100x100 histogram size, I want to find 2 highest values ​​A and b, and their index (a1, a2, a3) and (b1, b2, b3), such as:

  hist [a1] [a2] [a3] = a hist [b1] [b2] [b3] = b  

we hist.max ( ) Can get the most value easily, but how can we achieve X highest value in ndarray?

I understand that one normally uses np.argmax to get the price index, but in that case:

  hist.argmax (). Size = () for single range (i) for i: hist.argmax (i) .shape = (100, 100)  

How do I get a shape (3) Can I do a tube with a dimension?

You get the top k You can use previously, and then according to the size of the array according to those 1D index:

  & gt; & Gt; & Gt; Arr = np.arange (100 * 100 * 100). Refresh (100, 100, 100) & gt; & Gt; & Gt; Np.random.shuffle (arr) & gt; & Gt; & Gt; Index = N.P.gagepartition (arr.flatten (), -2) [- 2:]> gt; & Gt; & Gt; N. P. Vustack (N.P. Onwell_ Indics (Index, AR Shape)) T. Ere ([[97, 99, 98], [97, 99, 99]]))))) & Gt; & Gt; Arrival [9 7] [99] [9 8] 99 99 9 & gt; & Gt; & Gt; Advent [9 7] [99] [99] 99 99 99  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -