Python: Rearrange indices from np.where()

I think it’s a fallacy to think that you can algorithmically deduce the correct “flow-sequence” of the grid points, by examining the contents of the tuple ind.

Here’s an example that illustrates why:

0 0 0 0 0 0 0 0 0 0
A B C D E 0 0 0 0 0
0 0 0 0 F 0 0 0 0 0
0 0 0 0 G 0 0 0 0 0
0 0 0 I H 0 0 0 0 0
0 0 0 J K 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

This is a schematic representation of your grid matrix, where, if you follow the letters A, B, C, etc, you will get the sequence of the flow through the grid-elements.

However, note that, no matter how smart an algorithm is, it will be unable to choose between the two possible flows:

A, B, C, D, E, F, G, H, I, J, K

and

A, B, C, D, E, F, G, H, K, J, I

So, I think you will have to record the sequence explicitly yourself, rather than deduce it from the positions of the T values in the grid.

Any algorithm will stop at the ambiguity at the grid location H in the above example

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top