Given a matrix of non-negative numbers (of arbitrary dimension) and a number, get all multi-dimensional indices of the number in that list.
For example, let's say we have the list [[0,1,0],[1,0,0]]
and the number 1
. In the first list, we see one 1
at the second index. If we were using one-based indices, this would be index [1,2]
. In the second list, there is another 1
at the first index, so this would be index [2,1]
. The final list would be [[1,2], [2,1]]
.
Rules
- Standard loopholes apply
- Matrix will:
- only use non-negative numbers
- not be ragged
- never be empty
- every inner list will always have the same length at its depth
- always be at least 2-D, and never 1-D or 0-D
- You may take input/output in any reasonable format
- You can use one-based or zero-based indexes
- Built-ins are allowed, but I encourage giving non-builtin answers if you do use them
- This is code-golf, so shortest code wins
Test cases (zero-based indexes)
[[0, 1, 0], [1, 0, 0], [1, 1, 1]], 1 => [[0, 1], [1, 0], [2, 0], [2, 1], [2, 2]]
[[[2, 3, 4], [3, 1, 5]], [[0, 2, 3], [3, 2, 3]]], 3 => [[0, 0, 1], [0, 1, 0], [1, 0, 2], [1, 1, 0], [1, 1, 2]]
Position
does exactly this, even if the list is arbitrarily ragged. \$\endgroup\$