NumPy stack or append array to array

后端 未结 3 832
悲哀的现实
悲哀的现实 2021-01-27 13:50

I am starting with NumPy.

Given two np.arrays, queu and new_path:

queu = [ [[0 0]
          [0 1]]
       ]

new_p         


        
3条回答
  •  不思量自难忘°
    2021-01-27 14:29

    It's not completely clear to me how you've set up your arrays, but from the sound of it, np.vstack should indeed do what you are look for:

    In [30]: queue = np.array([0, 0, 0, 1]).reshape(2, 2)
    
    In [31]: queue
    Out[31]:
    array([[0, 0],
           [0, 1]])
    
    In [32]: new_path = np.array([0, 0, 1, 0, 2, 0]).reshape(3, 2)
    
    In [33]: new_path
    Out[33]:
    array([[0, 0],
           [1, 0],
           [2, 0]])
    
    In [35]: np.vstack((queue, new_path))
    Out[35]:
    array([[0, 0],
           [0, 1],
           [0, 0],
           [1, 0],
           [2, 0]])
    

提交回复
热议问题