# Apply Flux model to a matrix

**URL:** <https://discourse.julialang.org/t/apply-flux-model-to-a-matrix/55324>\
**Category:** Machine Learning\
**Created:** [February 15, 2021, 3:18pm UTC](https://discourse.julialang.org/t/apply-flux-model-to-a-matrix/55324 "2021-02-15T15:18:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon74562486](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@anon74562486](https://discourse.julialang.org/u/anon74562486)\
**Post date:** [February 15, 2021, 3:18pm UTC](https://discourse.julialang.org/t/apply-flux-model-to-a-matrix/55324/1 "2021-02-15T15:18:26Z")

</div>

I have a program that outputs a matrix and I have also a NN model that takes as input one element array.  
I want to apply the NN to every element of the matrix.  
I have tried in this way

```julia
my_model(x) = reshape(reshape(x, 1, :) |> model, size(x)) # takes the matrix, reshape it as 1xn matrix, apply the model on it and reshape the output as the input

```

the problemi is that the reshape function eats too memory and I can’t call GC.gc() after the function because I want to use the model in a Thread.@threads for.

What is the best way to apply a NN model to a data structure element by element?  
Thank you and sorry for my english.
