Numpy concatenate 2D arrays with 1D array

前端 未结 3 1831
轻奢々
轻奢々 2020-12-09 15:16

I am trying to concatenate 4 arrays, one 1D array of shape (78427,) and 3 2D array of shape (78427, 375/81/103). Basically this are 4 arrays with features for 78427 images,

3条回答
  •  情歌与酒
    2020-12-09 16:06

    You can try this one-liner:

    concat = numpy.hstack([a.reshape(dim,-1) for a in [Cscores, Mscores, Tscores, Yscores]])
    

    The "secret" here is to reshape using the known, common dimension in one axis, and -1 for the other, and it automatically matches the size (creating a new axis if needed).

提交回复
热议问题