# How to apply an activation function to a subset of output units?

**URL:** <https://discourse.julialang.org/t/how-to-apply-an-activation-function-to-a-subset-of-output-units/33202>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [January 10, 2020, 3:34pm UTC](https://discourse.julialang.org/t/how-to-apply-an-activation-function-to-a-subset-of-output-units/33202 "2020-01-10T15:34:37Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![johnbb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnbb/32/34233_2.png) [@johnbb](https://discourse.julialang.org/u/johnbb)\
**Post date:** [February 20, 2023, 11:19am UTC](https://discourse.julialang.org/t/how-to-apply-an-activation-function-to-a-subset-of-output-units/33202/4 "2023-02-20T11:19:54Z")

</div>

I have since the previous posting three years ago avoided the problem by adding a sufficiently high number to the targets whenever needed, but I would now like to keep the targets as they are.

Is there a better way than the following?

```julia
s(x::AbstractArray{Float32,2}) = vcat(x[[1], :], softplus(x[2:end, :]))
Chain(...., Dense(10, 10), s)

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-apply-an-activation-function-to-a-subset-of-output-units/33202)._
