Concatenate two numpy arrays in the 4th dimension

后端 未结 6 1460
一生所求
一生所求 2020-12-14 06:59

I have two numpy arrays with three dimensions (3 x 4 x 5) and I want to concatenate them so the result has four dimensions (3 x 4 x 5 x 2). In Matlab, this can be done with

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 07:29

    Here you go:

    import numpy as np
    a = np.ones((3,4,5))
    b = np.ones((3,4,5))
    c = np.concatenate((a[...,np.newaxis],b[...,np.newaxis]),axis=3)
    

提交回复
热议问题