# Binning a 2D array

**URL:** <https://discourse.julialang.org/t/binning-a-2d-array/46791>\
**Category:** New to Julia\
**Created:** [September 17, 2020, 4:40pm UTC](https://discourse.julialang.org/t/binning-a-2d-array/46791 "2020-09-17T16:40:07Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [September 17, 2020, 10:10pm UTC](https://discourse.julialang.org/t/binning-a-2d-array/46791/9 "2020-09-17T22:10:25Z")

</div>

If you always want a power-of-2 bin, repeated application of this works:

```julia
bin2(a) = a[1:2:end-1, 1:2:end-1] .+ a[2:2:end, 1:2:end-1] .+ a[1:2:end-1, 2:2:end] .+ a[2:2:end, 2:2:end]

```

---

_[View the full topic](https://discourse.julialang.org/t/binning-a-2d-array/46791)._
