enable_imperative

paddle.fluid.dygraph.enable_imperative(place=None)[source]

This function enables imperative mode.

Parameters

place (fluid.CPUPlace or fluid.CUDAPlace, optional) – Place for imperative execution. If None, the running place will be determined according to the way of paddle compilation. Default: None

Returns

None

Examples

import paddle.fluid as fluid

fluid.enable_imperative()  # Now we are in imperative mode
x = fluid.layers.ones( (2, 2), "float32")
y = fluid.layers.zeros( (2, 2), "float32")
z = x + y
print( z.numpy() )   #[[1, 1], [1, 1]]