# Find the index of a bin where a value between two bin value

**URL:** <https://discourse.julialang.org/t/find-the-index-of-a-bin-where-a-value-between-two-bin-value/32080>\
**Category:** General Usage\
**Created:** [December 10, 2019, 4:27am UTC](https://discourse.julialang.org/t/find-the-index-of-a-bin-where-a-value-between-two-bin-value/32080 "2019-12-10T04:27:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yusri-dh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yusri-dh/32/7404_2.png) [@yusri-dh](https://discourse.julialang.org/u/yusri-dh)\
**Post date:** [December 10, 2019, 4:27am UTC](https://discourse.julialang.org/t/find-the-index-of-a-bin-where-a-value-between-two-bin-value/32080/1 "2019-12-10T04:27:26Z")

</div>

Is there any related function in julia like numpy.digitize? Basically I want to find the index of a bin where a value between two bin value. Here is the example from numpy

```julia
>>> my_list = [3,2,56,4,32,4,7,88,4,3,4]
>>> bins = [0,20,40,60,80,100]
>>> np.digitize(my_list,bins)
array([1, 1, 3, 1, 2, 1, 1, 5, 1, 1, 1])

```

---

<div class="post-metadata">

**Author:** ![robsmith11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robsmith11/32/29641_2.png) [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Post date:** [December 10, 2019, 5:10am UTC](https://discourse.julialang.org/t/find-the-index-of-a-bin-where-a-value-between-two-bin-value/32080/2 "2019-12-10T05:10:23Z")

</div>

```julia
julia> searchsortedfirst.(Ref(bins), my_list)
11-element Array{Int64,1}:
 2
 2
 4
 2
 3
 2
 2
 6
 2
 2
 2

```

---

<div class="post-metadata">

**Author:** ![yusri-dh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yusri-dh/32/7404_2.png) [@yusri-dh](https://discourse.julialang.org/u/yusri-dh)\
**Post date:** [December 11, 2019, 5:08am UTC](https://discourse.julialang.org/t/find-the-index-of-a-bin-where-a-value-between-two-bin-value/32080/3 "2019-12-11T05:08:37Z")

</div>

Thank you, this is exactly what I need
