Hi I Have a lage list with Fals/True items.
I would like to count the number of True items.
Normally I use the Mass addition component but this is quite slow…
Any suggestions for an alternative?
Many thanks
Hi I Have a lage list with Fals/True items.
I would like to count the number of True items.
Normally I use the Mass addition component but this is quite slow…
Any suggestions for an alternative?
Many thanks
The overhead there is obviously converting integers to Boolean. Skipping that, Cull Pattern has the overhead internally. Python is only slightly faster than MA summing integers or Booleans. ‘List access’ and ‘No Type Hint’ on the Python ‘x’ input. If type hint is ‘bool’, it’s almost as slow as the others (4.9s). Advantage over MA is insignificant.
sum = 0
for k in range(len(x)):
sum += x[k];
a = sum
P.S. Oh, wait! Python has a 'sum()’ function that is faster, as long as Python ‘x’ input is ‘No Type Hint’. 139ms for integers, 204ms for Booleans.
a = sum(x)