I have an empty numpy array. And I want to append arrays to it such that each appended array becomes an element.
import numpy as np
a = np.array([])
for i in range(3):
a=np.append(a,np.array(['x','y','z']))
print(a)
My expected outcome is : a= [['x','y','z'],['x','y','z'],['x','y','z']] but this seems to be impossible without adding axis=1 and handling the first append differently. This adds to unnecessary if condition every time in loop. Same is the problem while using vstack also. The first insert to the array has to happen with a hstack and the subsequent ones with a vstack.
What is the best way to achieve this in numpy?
TIA :)
a, like (0,3) shape. And add a (1,3) shape each loop. And make sure each has the correct dtype. And useaxis=0. The goal is a (n,3) array. Keep that in mind.