chainer.functions.stack(xs, axis=0)[source]

Variableを新しい軸に添って結合する。

 

Parameters:
  • xs (list of Variable or numpy.ndarray or cupy.ndarray) – 結合される入力Variables。Variables は全ておなじshapeでなければならない。
  • axis (int) – 配列がスタックされるとき基準にする軸。 axis パラメータは、ndim1axisndim−ndim−1≤axis≤ndim. (ndim は入力値の次元数 )のとき、受け入れ可能。 axis<0axis<0の場合、結果はndim+1|axis|ndim+1−|axis|と同じサイズ。
Returns:

出力値。 x_1, x_2, ..., x_n と y を入力値と出力値とし、 y[:, ..., 0, ..., :] は x_1、 y[:, ..., 1, ..., :] は x_2 そして y[:, ..., n-1, ..., :] は x_n (インデクスされた軸は axisを示す)

Return type:

Variable

 

Example

 


>>> x1 = np.arange(0, 12).reshape(3, 4)

>>> x1.shape (3, 4)
>>> x1
array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]])
>>> x2 = np.arange(12, 24).reshape(3, 4)
>>> x2.shape (3, 4)
>>> x2
array([[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]])
>>> y = F.stack([x1, x2], axis=0)
>>> y.shape (2, 3, 4)
>>> y.data
array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]],
[[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]])
>>> y = F.stack([x1, x2], axis=1)
>>> y.shape (3, 2, 4)
>>> y.data
array([[[ 0, 1, 2, 3], [12, 13, 14, 15]],
[[ 4, 5, 6, 7], [16, 17, 18, 19]],
[[ 8, 9, 10, 11], [20, 21, 22, 23]]])
>>> y = F.stack([x1, x2], axis=2)
>>> y.shape (3, 4, 2)
>>> y.data
array([[[ 0, 12], [ 1, 13], [ 2, 14], [ 3, 15]],
[[ 4, 16], [ 5, 17], [ 6, 18], [ 7, 19]],
[[ 8, 20], [ 9, 21], [10, 22], [11, 23]]])
>>> y = F.stack([x1, x2], axis=-1)
>>> y.shape (3, 4, 2)