mindspore.nn.Sigmoid

View Source On Gitee
class mindspore.nn.Sigmoid[source]

Sigmoid activation function.

Applies sigmoid-type activation element-wise.

Sigmoid function is defined as:

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

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

Sigmoid Activation Function Graph:

../../_images/Sigmoid.png
Inputs:
  • input_x (Tensor) - 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_x.

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

  • TypeError – If input_x is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

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