Concatenating empty array in Numpy

后端 未结 6 476
情歌与酒
情歌与酒 2021-01-30 16:04

in Matlab I do this:

>> E = [];
>> A = [1 2 3 4 5; 10 20 30 40 50];
>> E = [E ; A]

E =

     1     2     3     4     5
    10    20    30    4         


        
6条回答
  •  失恋的感觉
    2021-01-30 16:50

    In Python, if possible to work with the individual vectors, to append you should use list.append()

    >>> E = []
    >>> B = np.array([1,2,3,4,5])
    >>> C = np.array([10,20,30,40,50])
    >>> E = E.append(B)
    >>> E = E.append(C)
    [array([1, 2, 3, 4, 5]), array([10, 20, 30, 40, 50])]
    

    and then after all append operations are done, return to np.array thusly

    >>> E = np.array(E)
    array([[ 1,  2,  3,  4,  5],
       [10, 20, 30, 40, 50]])
    

提交回复
热议问题