# Taking variable as independent with Zygote (Automatic differentiation)

**URL:** https://discourse.julialang.org/t/taking-variable-as-independent-with-zygote-automatic-differentiation/76159
**Category:** General Usage
**Tags:** zygote, autodiff
**Created:** [February 10, 2022, 12:18pm UTC](https://discourse.julialang.org/t/taking-variable-as-independent-with-zygote-automatic-differentiation/76159 "2022-02-10T12:18:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Eriklw](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@Eriklw](https://discourse.julialang.org/u/Eriklw)
#### Post date: [February 10, 2022, 12:18pm UTC](https://discourse.julialang.org/t/taking-variable-as-independent-with-zygote-automatic-differentiation/76159/1 "2022-02-10T12:18:57Z")

</div>

I have a function that I want to take the gradient of in the end. I want to achive that a certain variable is deemed independent of the variable i wish to differentiate in the the end. I tried to do this with the Zygote.ignore() function but this does not seem to work:

```julia
function test(A)
    Zygote.ignore() do
        B = A
    end
    c = norm(A*B)
return c
end

A = rand(5,5)
test(A)

```

Here I would in the end take the gradient with respect to A…  
This seems to create B only as a local variable within the “do-Block”. Is there a way around this?

---

<div class="post-metadata">

### Author: ![trahflow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trahflow/32/30585_2.png) [@trahflow](https://discourse.julialang.org/u/trahflow)
#### Post date: [February 10, 2022, 12:36pm UTC](https://discourse.julialang.org/t/taking-variable-as-independent-with-zygote-automatic-differentiation/76159/2 "2022-02-10T12:36:05Z")

</div>

```julia
function test(A)
    B = Zygote.@ignore A
    norm(A * B)
end

```
