chainer.as_variable¶
-
chainer.
as_variable
(obj)[source]¶ Converts an array or a variable into
Variable
.This is a convenient function to get a
Variable
object transparently from a raw array or a variable.Note that this function should only be used for type consistency (i.e., to enforce the return value of an API having type
Variable
). Therequires_grad
flag is kept as is; ifobj
is a raw array, the newly created variable hasrequires_grad = False
. In order to make a variable w.r.t. which you want to compute the gradient, you should useVariable
directly.- Parameters
obj (numpy.ndarray or cupy.ndarray or Variable) – An array or a variable that you want to convert to
Variable
.- Returns
A variable converted from
obj
. Ifobj
is a raw array, this is a newVariable
object that wraps the array. Ifobj
is already aVariable
object, this function returnsobj
as is.- Return type