# How can I sum an ArrayExpression?

**URL:** <https://discuss.hail.is/t/how-can-i-sum-an-arrayexpression/2595>\
**Category:** Hail Query & hailctl\
**Created:** [April 8, 2022, 6:00pm UTC](https://discuss.hail.is/t/how-can-i-sum-an-arrayexpression/2595 "2022-04-08T18:00:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ldgauthier](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ldgauthier/32/754_2.png) [@ldgauthier](https://discuss.hail.is/u/ldgauthier)\
**Post date:** [April 8, 2022, 6:00pm UTC](https://discuss.hail.is/t/how-can-i-sum-an-arrayexpression/2595/1 "2022-04-08T18:00:17Z")

</div>

The concordance method is super handy, but I want the discordance rate per sample. How can I sum the entries of the concordance table in each row of the sample results? Most things I’ve tried result in  
\<ArrayExpression of type array\<array\>\> object is not iterable

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [April 11, 2022, 1:25pm UTC](https://discuss.hail.is/t/how-can-i-sum-an-arrayexpression/2595/2 "2022-04-11T13:25:38Z")

</div>

I think the way to do this is probably something like:

```auto
all_indices = hl.flat_map(lambda i: hl.range(5).map(lambda j: (i, j)), hl.range(5))
discordant_indices = all_indices.filter(lambda elt: elt[0] != elt[1])
ht = ht.annotate(concordance_ratio = hl.sum(discordant_indices.map(lambda elt: ht.concordance[elt[0]][elt[1]]) / hl.sum(hl.range(5).map(lambda i: ht.concordance[i][i]))

```

---

<div class="post-metadata">

**Author:** ![ldgauthier](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ldgauthier/32/754_2.png) [@ldgauthier](https://discuss.hail.is/u/ldgauthier)\
**Post date:** [April 11, 2022, 9:39pm UTC](https://discuss.hail.is/t/how-can-i-sum-an-arrayexpression/2595/3 "2022-04-11T21:39:22Z")

</div>

Awesome, you saved me a LOT of time – thanks!!!
