to_variable

paddle.fluid.dygraph.to_variable(value, block=None, name=None)[source]

The API will create a Variable object from numpy.ndarray or Variable object.

Parameters
  • value (ndarray) – The numpy.ndarray object that needs to be converted, it can be multi-dimension, and the data type is one of numpy.{float16, float32, float64, int16, int32, int64, uint8, uint16}.

  • block (fluid.Block, optional) – Which block this variable will be in. Default: None.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name

Returns

Tensor created from the specified numpy.ndarray object, data type and shape is the same as value .

Return type

Variable

Examples

import numpy as np
import paddle.fluid as fluid

with fluid.dygraph.guard():
    x = np.ones([2, 2], np.float32)
    y = fluid.dygraph.to_variable(x)