Appending np.arrays to a blank array in Python
Question: I am trying to save the results from a loop in a np.array.

    
    
        import numpy as np
        p=np.array([])
        points= np.array([[3,0,0],[-1,0,0]])
    
        for i in points:
           for j in points:
              if j[0]!=0:
                 n=i+j
           p= np.append(p,n)
    

However the resulting array is a 1D array of 6 members.

    
    
        [2.  0.  0. -2.  0.  0.]
    

Instead I am looking for, but have been unable to produce:

    
    
        [[2,0,0],[-2,0,0]]
    

Is there any way to get the result above?

Thank you.


Answer: One possibility is to turn `p` into a list, and convert it into a NumPy array
right at the end:

    
    
    p = []
    for i in points:
       ...
       p.append(n)
    p = np.array(p)
    

