neg

paddle. neg ( x: Tensor, name: str | None = None ) Tensor [source]

This function computes the negative of the Tensor elementwisely.

Parameters
  • x (Tensor) – Input of neg operator, an N-D Tensor, with data type bfloat16, float16, float32, float64, int8, int16, int32, int64, uint8, complex64, complex128.

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to api_guide_Name.

Returns

The negative of input Tensor. The shape and data type are the same with input Tensor.

Return type

out (Tensor)

Examples

>>> import paddle

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = paddle.neg(x)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[ 0.40000001,  0.20000000, -0.10000000, -0.30000001])