# How to unpack result from extrema function

**URL:** https://discourse.julialang.org/t/how-to-unpack-result-from-extrema-function/8406
**Category:** General Usage
**Created:** [January 16, 2018, 5:02pm UTC](https://discourse.julialang.org/t/how-to-unpack-result-from-extrema-function/8406 "2018-01-16T17:02:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Paethon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paethon/32/9278_2.png) [@Paethon](https://discourse.julialang.org/u/Paethon)
#### Post date: [January 16, 2018, 5:02pm UTC](https://discourse.julialang.org/t/how-to-unpack-result-from-extrema-function/8406/1 "2018-01-16T17:02:26Z")

</div>

Hi

I have a multi dimensional array and previously used minimum() and maximum() to scale the entries between 0 and 1 independently along one of the dimensions.

```julia
arr = randn(3,128,128,1000)
mi = minimum(arr, (2,3,4))
ma = maximum(arr, (2,3,4))
@. arr = (arr - mi) / (ma - mi)

```

Obviously it would be faster to use extrema instead. The obvious solution unfortunately does not work:

```julia
arr = randn(3,128,128,1000)
mi, ma = extrema(arr, (2,3,4))
@. arr = (arr - mi) / (ma - mi)

```

Because extrema does not return a tuple of arrays (as I would have expected) but an array of tuples. I could come up with the following solution, but it does not really seem like a sane thing to do just to get the extrema in a usable form.

```julia
arr = randn(3,128,128,1000)

ex = extrema(arr, (2,3,4))
ex = hcat([collect(i) for i in ex[:,1,1,1]]...)'
mi = reshape(ex[:,1],3,1,1,1)
ma = reshape(ex[:,2],3,1,1,1)

@. arr = (arr - mi) / (ma - mi)

```

So now to my question: Is there a version of extrema (or a way of calling it) that gives me a tuple of arrays? If this does not exist: What is the best/most readable/ideomatic way of converting the one into the other?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [January 16, 2018, 5:09pm UTC](https://discourse.julialang.org/t/how-to-unpack-result-from-extrema-function/8406/2 "2018-01-16T17:09:32Z")

</div>

```julia
arr = randn(3,128,128,1000)
extr = extrema(arr, (2,3,4))
first.(extr), last.(extr)

```

---

<div class="post-metadata">

### Author: ![Paethon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paethon/32/9278_2.png) [@Paethon](https://discourse.julialang.org/u/Paethon)
#### Post date: [January 16, 2018, 5:13pm UTC](https://discourse.julialang.org/t/how-to-unpack-result-from-extrema-function/8406/3 "2018-01-16T17:13:39Z")

</div>

I did not think of that!  
Thank you so much 🙂

I still think extrema should return a tuple of arrays though 😃
