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

**URL:** <https://discuss.hail.is/t/how-do-i-get-a-count-of-trues-falses-present-in-a-tables-row-field/1334>\
**Category:** Hail Query & hailctl\
**Created:** [March 13, 2020, 1:56pm UTC](https://discuss.hail.is/t/how-do-i-get-a-count-of-trues-falses-present-in-a-tables-row-field/1334 "2020-03-13T13:56:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnc1231](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnc1231/32/286_2.png) [@johnc1231](https://discuss.hail.is/u/johnc1231)\
**Post date:** [March 13, 2020, 1:56pm UTC](https://discuss.hail.is/t/how-do-i-get-a-count-of-trues-falses-present-in-a-tables-row-field/1334/1 "2020-03-13T13:56:01Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![johnc1231](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnc1231/32/286_2.png) [@johnc1231](https://discuss.hail.is/u/johnc1231)\
**Post date:** [March 13, 2020, 1:57pm UTC](https://discuss.hail.is/t/how-do-i-get-a-count-of-trues-falses-present-in-a-tables-row-field/1334/2 "2020-03-13T13:57:02Z")

</div>

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

```auto
# 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:

```auto
[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}]

```
