# Aggregating a numeric array

**URL:** https://discuss.hail.is/t/aggregating-a-numeric-array/3686
**Category:** Hail Query & hailctl
**Created:** [December 14, 2023, 3:07pm UTC](https://discuss.hail.is/t/aggregating-a-numeric-array/3686 "2023-12-14T15:07:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MsUTR](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@MsUTR](https://discuss.hail.is/u/MsUTR)
#### Post date: [December 14, 2023, 3:07pm UTC](https://discuss.hail.is/t/aggregating-a-numeric-array/3686/1 "2023-12-14T15:07:09Z")

</div>

Hello all. I am trying to process the Hail table from gnomAD v4. In the hail table, there is a row field called freq with this schema:

```python
Row fields:
    'locus': locus<GRCh38> 
    'alleles': array<str> 
    'freq': array<struct {
        AC: int32, 
        AF: float64, 
        AN: int32, 
        homozygote_count: int64
    }> 

```

I want to annotate a new row that aggregates the entire array of ht.freq.AC per row, I tried it with this method but it didn’t work:

```python
ht = ht.annotate(freq_AC_sum=hl.agg.array_sum(ht.freq.AC))
ExpressionException: 'Table.annotate: field 'freq_AC_sum'' does not support aggregation

```

May I please get some advice on how I can do that? Thank you very much.

---

<div class="post-metadata">

### Author: ![Wen\_He](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/wen_he/32/1110_2.png) [@Wen\_He](https://discuss.hail.is/u/Wen_He)
#### Post date: [April 5, 2024, 1:42pm UTC](https://discuss.hail.is/t/aggregating-a-numeric-array/3686/2 "2024-04-05T13:42:07Z")

</div>

Hi Do you find any solution? thanks

---

<div class="post-metadata">

### Author: ![patrick-schultz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/patrick-schultz/32/265_2.png) [@patrick-schultz](https://discuss.hail.is/u/patrick-schultz)
#### Post date: [April 11, 2024, 12:38pm UTC](https://discuss.hail.is/t/aggregating-a-numeric-array/3686/3 "2024-04-11T12:38:42Z")

</div>

Apologies for the delayed response to both of you!

You can aggregate over an array expression `a` using `a.aggregate`. So the above example would be

```python
ht = ht.annotate(freq_AC_sum=ht.freq.aggregate(lambda freq: hl.agg.sum(freq.AC))

```

In the special case of computing the sum of an array, you can also use `hl.sum`. So if `ht.AC` were a top-level array field, you could do

```python
ht = ht.annotate(freq_AC_sum=hl.sum(ht.AC))

```

I know the naming isn’t super clear, but the `hl.agg.array_sum` aggregator is for aggregating many array fields of the same length, producing an array of the elementwise aggregates.
