chainer.functions.cast(x, typ)[source]

入力値を与えられた型にキャストする。

 

Parameters:
  • x (Variable or numpy.ndarray or cupy.ndarray) –キャストされる入力値。A(s_1, s_2, ..., s_N)型のfloat配列。
  • typ (str of dtype or numpy.dtype) – Typecode or data type to cast.キャストするタイプコード、もしくはデータ・タイプ。
Returns:

キャストされた配列を保持しているVariable。

Return type:

Variable

 

Example

 


>>>
x = np.arange(0, 3, dtype=np.float64)
>>> x.dtype
dtype('float64')
>>> y = F.cast(x, np.float32)
>>> y.dtype
dtype('float32')
>>> y = F.cast(x, 'float16')
>>> y.dtype
dtype('float16')