# Zygote.gradient(): Mutating arrays is not supported

**URL:** <https://discourse.julialang.org/t/zygote-gradient-mutating-arrays-is-not-supported/45148>\
**Category:** General Usage\
**Created:** [August 18, 2020, 9:12am UTC](https://discourse.julialang.org/t/zygote-gradient-mutating-arrays-is-not-supported/45148 "2020-08-18T09:12:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![F-YF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/f-yf/32/17363_2.png) [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Post date:** [August 18, 2020, 9:12am UTC](https://discourse.julialang.org/t/zygote-gradient-mutating-arrays-is-not-supported/45148/1 "2020-08-18T09:12:55Z")

</div>

When I do a gradient calculation with Zygote, it throw an error: Mutating arrays is not supported. I don’t know why it went wrong, how should I correct it, or how should I debug it so that I would know where it went wrong.

Mutating arrays is not supported

Stacktrace:  
[1] error(::String) at .\error.jl:33  
[2] (::Zygote.var"#451#452")(::Nothing) at C:\Users\38606.julia\packages\Zygote\seGHk\src\lib\array.jl:65  
[3] (::Zygote.var"#2373#back#453"{Zygote.var"#451#452"})(::Nothing) at C:\Users\38606.julia\packages\ZygoteRules\6nssF\src\adjoint.jl:49  
[4] Square\_T0 at .\In[2]:13 [inlined]  
[5] (::typeof(∂(Square\_T0)))(::Nothing) at C:\Users\38606.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0  
[6] hotrg at .\In[13]:5 [inlined]  
[7] (::typeof(∂(hotrg)))(::Float64) at C:\Users\38606.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0  
[8] #70 at .\In[19]:1 [inlined]  
[9] (::Zygote.var"#41#42"{typeof(∂(#70))})(::Float64) at C:\Users\38606.julia\packages\Zygote\seGHk\src\compiler\interface.jl:45  
[10] gradient(::Function, ::Array{Complex{Float64},2}, ::Vararg{Array{Complex{Float64},2},N} where N) at C:\Users\38606.julia\packages\Zygote\seGHk\src\compiler\interface.jl:54  
[11] top-level scope at In[19]:1

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [August 18, 2020, 10:01am UTC](https://discourse.julialang.org/t/zygote-gradient-mutating-arrays-is-not-supported/45148/2 "2020-08-18T10:01:42Z")

</div>

Probably, you try to differentiate through some code that contains something like `x[i] = y`.  
This is not supported by Zygote. I used [this work-around](https://discourse.julialang.org/t/zygote-and-setindex/44554) at some point.

To get more help, please follow the recommendations in [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757).
