mindspore.ops.neg

mindspore.ops.neg(x)[source]

Returns a tensor with negative values of the input tensor element-wise.

\[out_{i} = - x_{i}\]
Parameters

x (Tensor) – The input tensor with a dtype of Number, its rank must be in [0, 7] inclusive.

Returns

Tensor, has the same shape and dtype as input.

Raises

TypeError – If x is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.array([1, 2, -1, 2, 0, -3.5]), mindspore.float32)
>>> output = ops.neg(x)
>>> print(output)
[-1.  -2.   1.  -2.   0.   3.5]