gradient

paddle.Tensor. gradient ( self )

Warning

API “paddle.base.dygraph.tensor_patch_methods.gradient” is deprecated since 2.1.0, and will be removed in future versions. Reason: Please use tensor.grad, which returns the tensor value of the gradient.

Warning

This API will be deprecated in the future, it is recommended to use x.grad which returns the tensor value of the gradient.

Get the Gradient of Current Tensor.

Returns

Numpy value of the gradient of current Tensor

Return type

ndarray

Examples

>>> import paddle

>>> x = paddle.to_tensor(5., stop_gradient=False)
>>> y = paddle.pow(x, 4.0)
>>> y.backward()
>>> print("grad of x: {}".format(x.gradient()))
grad of x: 500.0