scope_guard_cn.rst 595 字节
Newer Older
H
Hao Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
.. _cn_api_fluid_scope_guard:

scope_guard
-------------------------------

.. py:function:: paddle.fluid.scope_guard(scope)


修改全局/默认作用域(scope),  运行时中的所有变量都将分配给新的scope。

参数:
  - **scope** - 新的全局/默认 scope。

**代码示例**

.. code-block:: python

  import paddle.fluid as fluid
  import numpy
  
  new_scope = fluid.Scope()
  with fluid.scope_guard(new_scope):
       fluid.global_scope().var("data").get_tensor().set(numpy.ones((2, 2)), fluid.CPUPlace())
  numpy.array(new_scope.find_var("data").get_tensor())