LoginSignup
1
0

More than 3 years have passed since last update.

numpy.ndarrayの連結

Posted at

以下記事を参考にしています。
http://tanukigraph.hatenablog.com/entry/2017/08/23/195756

忘れやすいのでメモ。

import numpy as np

a = np.array([[1,2],[3,4]])
b = np.array([[5,6],[7,8]])
c = np.array([[1,2],[3,4],[5,6]])

1. (2,2)×2 -> (4,2)

np.concatenate([a,b],axis=0)

# output
array([[1, 2],
       [3, 4],
       [5, 6],
       [7, 8]])

※concatnateで次元を上げることはできない

2. (2,2)×2 -> (2,2,2)

パターン1

np.stack([a,b],axis=0)

# output
array([[[1, 2],
        [3, 4]],

       [[5, 6],
        [7, 8]]])

パターン2

np.stack([a,b],axis=1)

array([[[1, 2],
        [5, 6]],

       [[3, 4],
        [7, 8]]])
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0