In Python, I am trying to initialize 2-element arrays of zeros within a size N by N array. The code I'm using works but I'm looking for something more efficient and elegant:
array1 = np.empty((N,N), dtype=object)
for i in range(N):
for j in range(N):
array1[i,j] = np.zeros(2, dtype=np.int)
Thank ahead for the help
(N,N,2)will work?N=2with your code you getarray1 = array([[array([0, 0]), array([0, 0])], [array([0, 0]), array([0, 0])]], dtype=object)), a3Darray (size NxNx2 for instance) or a big2Darray (size 2Nx2N)? Maybe there would be a better solution to your code problem than what you got with this sample... Tell us more!np.zeros(N,N,2)?