Concatenate 3 unidimensional arrays together in numpy

前端 未结 3 940
暗喜
暗喜 2021-01-23 01:52

I\'m leaving MatLab for numpy and in general it\'s going ok, but I\'m having a nightmare finding a nice pythonic way to do what would have done this in MatLab:

A         


        
相关标签:
3条回答
  • 2021-01-23 02:21
    >>> C=np.array([A,B,B])
    >>> C
    array([[1, 2, 3, 4],
           [5, 6, 7, 8],
           [5, 6, 7, 8]])
    

    or:

    >>> C=np.array([A,B,B]).swapaxes(1,0)
    >>> C
    array([[1, 5, 5],
           [2, 6, 6],
           [3, 7, 7],
           [4, 8, 8]])
    
    0 讨论(0)
  • 2021-01-23 02:41

    You can use np.c_[A,B,B], which gives

    array([[1, 5, 5],
           [2, 6, 6],
           [3, 7, 7],
           [4, 8, 8]])
    
    0 讨论(0)
  • 2021-01-23 02:47

    I would use dstack

    >>> A=np.array([1,2,3,4])
    >>> B=np.array([5,6,7,8])
    >>> np.dstack((A, B, B))
    array([[[1, 5, 5],
            [2, 6, 6],
            [3, 7, 7],
            [4, 8, 8]]])
    
    0 讨论(0)
提交回复
热议问题