mindspore.nn.Sigmoid

class mindspore.nn.Sigmoid[source]

Applies sigmoid activation function element-wise.

Sigmoid function is defined as:

\[\text{sigmoid}(x_i) = \frac{1}{1 + \exp(-x_i)},\]

where \(x_i\) is the element of x.

Sigmoid Activation Function Graph:

../../_images/Sigmoid.png
Inputs:
  • input (Tensor) - input is \(x\) in the preceding formula. Tensor of any dimension, the data type is float16, float32, float64, complex64 or complex128.

Outputs:

Tensor, with the same type and shape as the input.

Raises
  • TypeError – If dtype of input is not float16, float32, float64, complex64 or complex128.

  • TypeError – If input is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, nn
>>> import numpy as np
>>> input = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
>>> sigmoid = nn.Sigmoid()
>>> output = sigmoid(input)
>>> print(output)
[0.2688  0.11914 0.5     0.881   0.7305 ]