A very short version of my list named "fire" is
fire = {{0, 0, 0, 20, 0, 0}, {0, 0, 0, 20, 0, 0}, {0, 0, 20, 20, 0, 0}}
.
For the first sublist Length[TakeWhile[fire[[1]], # < 20 &]]
, calculates the number of preceding "0" before 20 shows up. In this case I get 3. The number of preceding 0 before 20 or the end of the sublist shows up is my ultimate goal.
Since my true list has 1000 of these sublists of six numbers I tried to map the function Length[TakeWhile[fire...]
. However, MapApply
or Map
did not work. The problem seems to identy the subsequent elements of fire within the expression. Any help is highly appreciated.
Length@First@SplitBy[#, 20] & /@ fire
$\endgroup$f[x_] := Length[TakeWhile[x, # < 20 &]]; f /@ fire
$\endgroup$LengthWhile[#, EqualTo[0]] & /@ fire
? Assuming the only possible values are0
or20
, at least, if the lists here are good examples. $\endgroup$Position[fire[[1]], 20][[1, 1]] - 1
yields the expected3
. $\endgroup$