Concatenating empty array in Numpy

后端 未结 6 541
情歌与酒
情歌与酒 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:47

    E = np.array([
        
    ]).reshape(0, 5)
    print("E: \n{}\nShape {}\n".format(E, E.shape))
    
    A = np.vstack([
        [1, 2, 3, 4, 5], 
        [10, 20, 30, 40, 50]]
    )
    print("A:\n{}\nShape {}\n".format(A, A.shape))
    
    C = np.r_[
        E, 
        A
    ].astype(np.int32)
    
    print("C:\n{}\nShape {}\n".format(C, C.shape))
    
    E: 
    []
    Shape (0, 5)
    
    A:
    [[ 1  2  3  4  5]
     [10 20 30 40 50]]
    Shape (2, 5)
    
    C:
    [[ 1  2  3  4  5]
     [10 20 30 40 50]]
    Shape (2, 5)
    

提交回复
热议问题