# Sum true after mask

**URL:** <https://discuss.pytorch.org/t/sum-true-after-mask/58065>\
**Category:** Uncategorized\
**Created:** [October 13, 2019, 1:32am UTC](https://discuss.pytorch.org/t/sum-true-after-mask/58065 "2019-10-13T01:32:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snip3r77](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@snip3r77](https://discuss.pytorch.org/u/snip3r77)\
**Post date:** [October 13, 2019, 1:32am UTC](https://discuss.pytorch.org/t/sum-true-after-mask/58065/1 "2019-10-13T01:32:50Z")

</div>

Hi guys,

```auto
x = torch.tensor([[1,2], [3, 4], [5, 6]]) 
(x<2).numpy().sum()

```

I’m able to do the above but is there a way to do it just using torch?

Thanks.

---

<div class="post-metadata">

**Author:** ![albanD](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alband/32/215_2.png) [@albanD](https://discuss.pytorch.org/u/albanD)\
**Post date:** [October 13, 2019, 1:51am UTC](https://discuss.pytorch.org/t/sum-true-after-mask/58065/2 "2019-10-13T01:51:34Z")

</div>

The sum() method exists in torch. Simply removing the `.numpy()` will make it work.  
Do you see an error when you do that?

---

<div class="post-metadata">

**Author:** ![snip3r77](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@snip3r77](https://discuss.pytorch.org/u/snip3r77)\
**Post date:** [October 13, 2019, 4:01am UTC](https://discuss.pytorch.org/t/sum-true-after-mask/58065/3 "2019-10-13T04:01:31Z")

</div>

Indeed it is. Thanks
