paddle. neg ( x, name=None ) [source]

This function computes the negative of the Tensor elementwisely.

  • x (Tensor) – Input of neg operator, an N-D Tensor, with data type float32, float64, int8, int16, int32, or int64.

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


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

Return type

out (Tensor)


>>> 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])