gradient

paddle.Tensor. gradient ( self )

Warning: API “paddle.fluid.dygraph.varbase_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:

ndarray: Numpy value of the gradient of current Tensor

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()))
# [500.]