# How do I get a count of Trues / Falses present in a Table's row field?

I am trying to get counts of how many items in an array field are true/false for each index aggregating over all the rows where the number is the counts of true for that index aggregating over all the rows (Eg. an answer would look like [10,23,13] if I had arrays of length 3).

We are going to have to use `hl.agg.array_agg` here.

``````# This first line is just me making an example table with a bunch of random boolean arrays.
ht = ht = hl.utils.range_table(20).annotate(bool_array = hl.zeros(10).map(lambda x: hl.rand_unif(0, 1) < .5))
# Now, to get counts of trues:
true_counts = ht.aggregate(hl.agg.array_agg(lambda x: hl.agg.count_where(x), ht.bool_array))
print(true_counts)
# Falses:
false_counts = ht.aggregate(hl.agg.array_agg(lambda x: hl.agg.count_where(~x), ht.bool_array))
print(false_counts)
# Both at once:
both_at_once = ht.aggregate(hl.agg.array_agg(lambda x: hl.agg.counter(x), ht.bool_array))
print(both_at_once)
``````

This prints:

``````[10, 13, 8, 11, 10, 10, 10, 14, 12, 11]
[10, 7, 12, 9, 10, 10, 10, 6, 8, 9]
[{False: 10, True: 10}, {False: 7, True: 13}, {False: 12, True: 8}, {False: 9, True: 11}, {False: 10, True: 10}, {False: 10, True: 10}, {False: 10, True: 10}, {False: 6, True: 14}, {False: 8, True: 12}, {False: 9, True: 11}]
``````