Given the specification of extended (or "fantasy") indexing with integers , the guarantee that A[nonzero(flag)] == A[flag] also a guarantee that the values ββare sorted from low to high in the 1st case. However, in higher dimensions, the result (while βsortedβ) has a different structure than you might expect.
In short, given a 1-dimensional array of integers ind and a 1-dimensional array x for all valid i defined for ind , we have the following:
result[i] = x[ind[i]]
result takes the form ind and contains the values ββof x at the indices indicated by ind . This means that we can deduce that if x[flag] supports the original order x , and if x[nonzero(flag)] matches x[flag] , then nonzero(flag) should always produce indexes in sorted order.
The only catch is that for multidimensional arrays, indexes are stored as different arrays for each indexed dimension. In other words,
x[array([0, 1, 2]), array([0, 0, 0])]
equally
array([x[0, 0], x[1, 0], x[2, 0]])
Values ββare still sorted, but each dimension is split into its own array. (As a result, you can do interesting things with the broadcast, but that is beyond the scope of this answer.)
The only problem with this logic is that, to my great surprise, I cannot find an explicit operator to ensure that Boolean indexing preserves the original order of the array. Nevertheless, I am absolutely sure that this is so. More generally, it would be incredibly perverse if x[[True, True, True]] return the reverse version of x .