# List comprehension in Zygote

**URL:** <https://discourse.julialang.org/t/list-comprehension-in-zygote/41881>\
**Category:** General Usage\
**Tags:** zygote\
**Created:** [June 22, 2020, 7:02pm UTC](https://discourse.julialang.org/t/list-comprehension-in-zygote/41881 "2020-06-22T19:02:34Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [June 23, 2020, 1:03pm UTC](https://discourse.julialang.org/t/list-comprehension-in-zygote/41881/3 "2020-06-23T13:03:46Z")

</div>

Zygote works fine with array comprehensions. I use it frequently. Here’s a simple example:

```julia
using Zygote

x = rand(5)
y = rand(5)

f(y) = sum([x[i] * y[i] for i in eachindex(y)])

```

Then for my random x,y, I have:

```julia
julia> Zygote.gradient(f, y)
([0.20735224892728188, 0.023609460904363777, 0.8209142299297378, 0.5328550686359217, 0.11713217978556711],)

```

You would get better help here in the forum by posting a self contained minimal reproducible example that produces your error. See [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) for more details on getting help.

---

_[View the full topic](https://discourse.julialang.org/t/list-comprehension-in-zygote/41881)._
