Suppose I have a numpy array of arrays of length 4:
In [41]: arr
Out[41]:
array([[ 1, 15, 0, 0],
[ 30, 10, 0, 0],
[ 30, 20, 0, 0],
...,
[104, 139, 146, 75],
[ 9, 11, 146, 74],
[ 9, 138, 146, 75]], dtype=uint8)
I want to know:
- Is it true that
arr
includes[1, 2, 3, 4]
? - If it true what index of
[1, 2, 3, 4]
inarr
?
I want to find out it as fast as it possible.
Suppose arr
contains 8550420 elements. I've checked several methods with timeit
:
- Just for checking without getting index:
any(all([1, 2, 3, 4] == elt) for elt in arr)
. It tooks 15.5 sec in average on 10 runs on my machine for
-based solution:for i,e in enumerate(arr): if list(e) == [1, 2, 3, 4]: break
It tooks about 5.7 secs in average
Does exists some faster solutions, for example numpy based?