# How to handle vector like in numpy?

**URL:** <https://discourse.julialang.org/t/how-to-handle-vector-like-in-numpy/79167>\
**Category:** General Usage\
**Tags:** vector\
**Created:** [April 7, 2022, 1:39pm UTC](https://discourse.julialang.org/t/how-to-handle-vector-like-in-numpy/79167 "2022-04-07T13:39:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![egor](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@egor](https://discourse.julialang.org/u/egor)\
**Post date:** [April 7, 2022, 1:39pm UTC](https://discourse.julialang.org/t/how-to-handle-vector-like-in-numpy/79167/1 "2022-04-07T13:39:06Z")

</div>

Hello everyone, in python, I often use this construction from numpy to select the necessary elements of an array:

```julia
counter = (array >= threshold).sum()

```

Is there something similar for vectors in julia or is it just to use PyCall?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 7, 2022, 1:41pm UTC](https://discourse.julialang.org/t/how-to-handle-vector-like-in-numpy/79167/2 "2022-04-07T13:41:54Z")

</div>

There are a number of ways to do this. `sum(a for a in array if a>=threshold)` is probably the best, but if you want a more numpy-like syntax, you could use `sum(array.>=threshold)` (although this will probably be slower than the comprehension)

---

<div class="post-metadata">

**Author:** ![egor](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@egor](https://discourse.julialang.org/u/egor)\
**Post date:** [April 7, 2022, 1:45pm UTC](https://discourse.julialang.org/t/how-to-handle-vector-like-in-numpy/79167/3 "2022-04-07T13:45:42Z")

</div>

> [@Oscar\_Smith](#):
>
> `sum(a for a in array if a>=threshold)`

the first option is not exactly what I need, the values are added there, and I do not need the values themselves, but their number  
The second option works just fine, thanks!

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [April 7, 2022, 1:47pm UTC](https://discourse.julialang.org/t/how-to-handle-vector-like-in-numpy/79167/4 "2022-04-07T13:47:07Z")

</div>

You can simply do:

```julia
counter = sum(>=(threshold), array)

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [April 7, 2022, 1:56pm UTC](https://discourse.julialang.org/t/how-to-handle-vector-like-in-numpy/79167/5 "2022-04-07T13:56:11Z")

</div>

Or if you like typing more and being explicit:

```julia
count(>=(threshold), array)

```

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 7, 2022, 1:56pm UTC](https://discourse.julialang.org/t/how-to-handle-vector-like-in-numpy/79167/6 "2022-04-07T13:56:31Z")

</div>

oh, then replacing `sum` with `count` would fix mine.
