Q:

From argwhere to where?

Is there a fast way of getting the output of argwhere in the output of where format ?
Let me show you what I'm doing with a bit of code:
In [123]: filter = np.where(scores[:,:,:,4,:] > 21000)

In [124]: filter
Out[124]: 
(array([ 2,  2,  4,  4,  4,  4,  4,  4,  4,  4,  4, 23, 23, 23, 23, 23]),
 array([13, 13,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  5]),
 array([0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2]),
 array([44, 44,  0,  1,  2,  3,  6,  8, 12, 14, 22, 31, 58, 76, 82, 41]))

In [125]: filter2 = np.argwhere(scores[:,:,:,4,:] > 21000)

In [126]: filter2
Out[126]: 
array([[ 2, 13,  0, 44],
       [ 2, 13,  1, 44],
       [ 4,  4,  3,  0],
       [ 4,  4,  3,  1],
       [ 4,  4,  3,  2],
       [ 4,  4,  3,  3],
       [ 4,  4,  3,  6],
       [ 4,  4,  3,  8],
       [ 4,  4,  3, 12],
       [ 4,  4,  3, 14],
       [ 4,  4,  3, 22],
       [23,  4,  2, 31],
       [23,  4,  2, 58],
       [23,  4,  2, 76],
       [23,  4,  2, 82],
       [23,  5,  2, 41]])

In [150]: scores[:,:,:,4,:][filter]
Out[150]: 
array([ 21344.,  21344.,  24672.,  24672.,  24672.,  24672.,  25232.,
        25232.,  25232.,  25232.,  24672.,  21152.,  21152.,  21152.,
        21152.,  21344.], dtype=float16)

In [129]: filter2[np.argsort(scores[:,:,:,4,:][filter])]
Out[129]: 
array([[23,  4,  2, 31],
       [23,  4,  2, 58],
       [23,  4,  2, 76],
       [23,  4,  2, 82],
       [ 2, 13,  0, 44],
       [ 2, 13,  1, 44],
       [23,  5,  2, 41],
       [ 4,  4,  3,  0],
       [ 4,  4,  3,  1],
       [ 4,  4,  3,  2],
       [ 4,  4,  3,  3],
       [ 4,  4,  3, 22],
       [ 4,  4,  3,  6],
       [ 4,  4,  3,  8],
       [ 4,  4,  3, 12],
       [ 4,  4,  3, 14]])

129 is my desired output, so my code works, but I'm trying to make it as fast as possible. Should I get filter2 with np.array(filter).transpose() ? Is there something even better ?
Edit, trying to put it more clearly: I want a list of indices ordered by the value they return when applied to an array. To do that, I need both the output of np.where and np.argwhere, and I'm wondering what is the fastest way to switch from one output to the other, or if there's another of getting my result.

A:

Look at the code for argwhere:
return transpose(asanyarray(a).nonzero())

while where docs say:

where(condition, [x, y])
  If only condition is given, return condition.nonzero().

In effect, both use a.nonzero().  One uses it as is, the other transposes it.
In [933]: x=np.zeros((2,3),int)
In [934]: x[[0,1,0],[0,1,2]]=1
In [935]: x
Out[935]: 
array([[1, 0, 1],
       [0, 1, 0]])

In [936]: x.nonzero()
Out[936]: (array([0, 0, 1], dtype=int32), array([0, 2, 1], dtype=int32))
In [937]: np.where(x)   # same as nonzero()
Out[937]: (array([0, 0, 1], dtype=int32), array([0, 2, 1], dtype=int32))
In [938]: np.argwhere(x)
Out[938]: 
array([[0, 0],
       [0, 2],
       [1, 1]], dtype=int32)
In [939]: np.argwhere(x).T
Out[939]: 
array([[0, 0, 1],
       [0, 2, 1]], dtype=int32)

argwhere().T is the same as where except in a 2d rather than a tuple.
np.transpose(filter) and np.array(filter).T look equally good.  For a large array the time spent in nonzero is much larger than the time spent on these transformations.

