create_global_var

paddle.static. create_global_var ( shape, value, dtype, persistable=False, force_cpu=False, name=None ) [source]

This function creates a new tensor variable with value in the global block(block 0).

Parameters
  • shape (list[int]|tuple[int]) – Shape of the variable

  • value (float) – The value of the variable. The new created variable will be filled with it.

  • dtype (str) – Data type of the variable

  • persistable (bool, optional) – If this variable is persistable. Default: False

  • force_cpu (bool, optional) – Force this variable to be on CPU. Default: False

  • name (str, optional) – For detailed information, please refer to Name . Usually name is no need to set and None by default.

Returns

The created Variable

Return type

Variable

Examples

>>> import paddle
>>> paddle.enable_static()
>>> var = paddle.static.create_global_var(shape=[2,3], value=1.0, dtype='float32',
...                                persistable=True, force_cpu=True, name='new_var')