TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Implement Swish Activation

Activation Functions
Easy

Apply the Swish activation elementwise:

Swish⁡(x)=x σ(x)\operatorname{Swish}(x) = x\,\sigma(x)Swish(x)=xσ(x) σ(x)=11+e−x\sigma(x) = \frac{1}{1+e^{-x}}σ(x)=1+e−x1​

Here, xxx is each input value and σ\sigmaσ is the sigmoid function. Compute sigmoid without overflow and return a NumPy array with the same shape as the input.

Loading visualization...

Examples

Input: x = [0, 1, -1, 3]

Output: [0.0, 0.731059, -0.268941, 2.857722]

Explanation: Each value is multiplied by its sigmoid gate.

Input: x = [[1, -1], [2, -2]]

Output: [[0.731059, -0.268941], [1.761594, -0.238406]]

Hint 1

Use np.exp(-np.logaddexp(0.0, -x)) for a stable sigmoid.

Hint 2

Multiply the sigmoid array elementwise by x.

Requirements

  • Implement sigmoid with NumPy
  • Avoid exponential overflow
  • Apply Swish elementwise and preserve shape
  • Return a NumPy array of floating-point values

Constraints

  • x is a nonempty finite numeric list of any shape
  • x contains at most 1,000,000 values
  • Use NumPy only
Try Similar Problems
Relu ActivationGeluSigmoid NumpyElu ActivationLeaky Relu

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.
PrevNext

Implement Swish Activation

Activation Functions
Easy

Apply the Swish activation elementwise:

Swish⁡(x)=x σ(x)\operatorname{Swish}(x) = x\,\sigma(x)Swish(x)=xσ(x) σ(x)=11+e−x\sigma(x) = \frac{1}{1+e^{-x}}σ(x)=1+e−x1​

Here, xxx is each input value and σ\sigmaσ is the sigmoid function. Compute sigmoid without overflow and return a NumPy array with the same shape as the input.

Loading visualization...

Examples

Input: x = [0, 1, -1, 3]

Output: [0.0, 0.731059, -0.268941, 2.857722]

Explanation: Each value is multiplied by its sigmoid gate.

Input: x = [[1, -1], [2, -2]]

Output: [[0.731059, -0.268941], [1.761594, -0.238406]]

Hint 1

Use np.exp(-np.logaddexp(0.0, -x)) for a stable sigmoid.

Hint 2

Multiply the sigmoid array elementwise by x.

Requirements

  • Implement sigmoid with NumPy
  • Avoid exponential overflow
  • Apply Swish elementwise and preserve shape
  • Return a NumPy array of floating-point values

Constraints

  • x is a nonempty finite numeric list of any shape
  • x contains at most 1,000,000 values
  • Use NumPy only
Try Similar Problems
Relu ActivationGeluSigmoid NumpyElu ActivationLeaky Relu

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.