enable_imperative

paddle.fluid.dygraph.enable_imperative(place=None)[源代码]

该接口打开动态图模式。

参数

  • place (fluid.CPUPlace 或 fluid.CUDAPlace,可选) - 执行动态图的设备。若为None,则设备根据paddle的编译方式决定。默认值为 None

返回

代码示例

  1. import paddle.fluid as fluid
  2. fluid.dygraph.enable_imperative() # Now we are in imperative mode
  3. x = fluid.layers.ones( (2, 2), "float32")
  4. y = fluid.layers.zeros( (2, 2), "float32")
  5. z = x + y
  6. print( z.numpy() ) #[[1, 1], [1, 1]]