# Julia implementation of IDL's rebin?

**URL:** <https://discourse.julialang.org/t/julia-implementation-of-idls-rebin/67098>\
**Category:** General Usage\
**Tags:** array\
**Created:** [August 27, 2021, 1:08pm UTC](https://discourse.julialang.org/t/julia-implementation-of-idls-rebin/67098 "2021-08-27T13:08:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbrisard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbrisard/32/24712_2.png) [@sbrisard](https://discourse.julialang.org/u/sbrisard)\
**Post date:** [August 27, 2021, 1:08pm UTC](https://discourse.julialang.org/t/julia-implementation-of-idls-rebin/67098/1 "2021-08-27T13:08:25Z")

</div>

Hello,

I am looking for the Julia equivalent of IDL’s [rebin function](http://www.harrisgeospatial.com/docs/rebin.html). It basically applies a reduction function `f` to “macro-cells” of an array. For example, a `(M₁ * N₁, M₂ * N₂, …, Mₚ * Nₚ)` array, `x` would be transformed into a `(N₁, N₂, …, Nₚ)` array, `y`, where each cell of `y` is the result of applying `f` to a sub-array of `x`

```julia
y[i₁, i₂, …, iₚ] = f(x[s₁, s₂, …, sₚ]),

```

where `sₖ` is the following slice (hope I didn’t get indices wrong!)

```julia
sₖ = (iₖ * Nₖ):((iₖ+1) * Nₖ).

```

For _strided_ arrays, this is quite easily achieved using a little bit of stride magic. I proposed a Python implementation of fiew years ago : [https://github.com/sbrisard/rebin](https://github.com/sbrisard/rebin), based on the [discussion presented here](https://sbrisard.github.io/posts/20150330-orientation_correlations_among_rice_grains-03.html). Since then, another implementation has been published: [pydl.rebin](https://github.com/weaverba137/pydl/blob/main/pydl/rebin.py), which is probably more robust.

My question is: is there a Julia equivalent for this (extremely useful) function?

Thanks in advance!
