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). The requires_grad flag is kept as is; if obj is a raw array, the newly created variable has requires_grad = False. In order to make a variable w.r.t. which you want to compute the gradient, you should use Variable 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. If obj is a raw array, this is a new Variable object that wraps the array. If obj is already a Variable object, this function returns obj as is.

Return type

Variable