# Recursively generating a tuple from intermediate neural network outputs

**URL:** https://discourse.julialang.org/t/recursively-generating-a-tuple-from-intermediate-neural-network-outputs/51687
**Category:** New to Julia
**Created:** [December 11, 2020, 9:23pm UTC](https://discourse.julialang.org/t/recursively-generating-a-tuple-from-intermediate-neural-network-outputs/51687 "2020-12-11T21:23:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![maxfreu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxfreu/32/17468_2.png) [@maxfreu](https://discourse.julialang.org/u/maxfreu)
#### Post date: [December 11, 2020, 9:23pm UTC](https://discourse.julialang.org/t/recursively-generating-a-tuple-from-intermediate-neural-network-outputs/51687/1 "2020-12-11T21:23:19Z")

</div>

Hi, I have different neural network “encoders” and would like to generate a tuple containing the output of intermediate stages. The encoders and the number of their stages vary. So essentially I want to automate and flexibilise the following:

```julia
function foo(input, fs)
    x1 = f1(input)
    x2 = f2(x1)
    ...
    xn = fn(xn-1)
    return (x1,x2,...,xn)
end

```

I think there must be an easy solution, but I just can’t wrap my head around it.

---

<div class="post-metadata">

### Author: ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)
#### Post date: [December 11, 2020, 9:31pm UTC](https://discourse.julialang.org/t/recursively-generating-a-tuple-from-intermediate-neural-network-outputs/51687/2 "2020-12-11T21:31:02Z")

</div>

Looks like [Flux.activations](https://fluxml.ai/Flux.jl/stable/models/regularisation/#Flux.activations) might be what you need?

---

<div class="post-metadata">

### Author: ![maxfreu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxfreu/32/17468_2.png) [@maxfreu](https://discourse.julialang.org/u/maxfreu)
#### Post date: [December 12, 2020, 10:07am UTC](https://discourse.julialang.org/t/recursively-generating-a-tuple-from-intermediate-neural-network-outputs/51687/3 "2020-12-12T10:07:36Z")

</div>

Tail recursion it is… 💡  
That‘s why I love julia: jump to the source, look at it, understand it, use it.
