# Zygote gradient: problem with indexing constant arrays

**URL:** https://discourse.julialang.org/t/zygote-gradient-problem-with-indexing-constant-arrays/29871
**Category:** Machine Learning
**Created:** [October 13, 2019, 7:33pm UTC](https://discourse.julialang.org/t/zygote-gradient-problem-with-indexing-constant-arrays/29871 "2019-10-13T19:33:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![misha\_mikhasenko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/misha_mikhasenko/32/5060_2.png) [@misha\_mikhasenko](https://discourse.julialang.org/u/misha_mikhasenko)
#### Post date: [October 13, 2019, 7:33pm UTC](https://discourse.julialang.org/t/zygote-gradient-problem-with-indexing-constant-arrays/29871/1 "2019-10-13T19:33:00Z")

</div>

It looks super simple,

```julia
function h(pars)
    my_array = [1.0, 2.0, 3.0]
    indices = [2,3,1]
    #
    v = 0.0
    for (c,i) in zip(pars,indices)
        v += c * my_array[i]
    end
    return v
end
h([1.0,2.0,3.0]) # 11, fine

g(x) = gradient(pars->h(pars), x)
g([1.0,2.0,3.0]) # MethodError: no method matching getindex(::Nothing, ::Int64)

```

I wondering what happens, any ideas? Does `my_array` get lost at differentiation?

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [October 14, 2019, 12:28am UTC](https://discourse.julialang.org/t/zygote-gradient-problem-with-indexing-constant-arrays/29871/2 "2019-10-14T00:28:14Z")

</div>

I got that error yesterday in a different context.

```julia
add Zygote#master
add IRTools#master

```

allowed me to continue
