# ERROR: Output should be scalar; gradients are not defined for output

**URL:** <https://discourse.julialang.org/t/error-output-should-be-scalar-gradients-are-not-defined-for-output/52769>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 3, 2021, 9:16am UTC](https://discourse.julialang.org/t/error-output-should-be-scalar-gradients-are-not-defined-for-output/52769 "2021-01-03T09:16:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BaoBaoDeMeng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baobaodemeng/32/19155_2.png) [@BaoBaoDeMeng](https://discourse.julialang.org/u/BaoBaoDeMeng)\
**Post date:** [January 3, 2021, 9:16am UTC](https://discourse.julialang.org/t/error-output-should-be-scalar-gradients-are-not-defined-for-output/52769/1 "2021-01-03T09:16:57Z")

</div>

using Flux

> W\_1 = rand(2)
> 
> W\_2 = rand(2)
> 
> W\_3 = rand(2)  
> b\_1 = rand(2)
> 
> b\_2 = rand(1)  
> function z(x,t)  
> return (W\_1_x+W\_2_t+b\_1)  
> end
> 
> function sigmod(u)  
> return 1/(1+exp(-u))  
> end
> 
> function g\_u(x,t)  
> return sum([sigmod(z(x,t)[1]) sigmod(z(x,t)[2])]\*W\_3+b\_2)  
> end

> x,t = rand(1,1), rand(1,1)  
> dg\_u(x,t) = gradient(g\_u,x,t)[1]  
> ddg\_u(x,t) = gradient(dg\_u,x,t)[1]  
> ERROR: Output should be scalar; gradients are not defined for output

How do we solve this second derivative problem???
