When you initialize a numpy array by np.empty(), it allocates enough space for you, but the values inside these supposedly empty cells will be random rubbish. E.g.
>>> a = np.empty(5,dtype = int)
>>> a
array([-2305843009213693952, -2305843009213693952, 4336320554,
0, 0])
>>> k = np.empty(5,dtype = int)
>>> k
array([-2305843009213693952, -2305843009213693952, 4336320556,
4294967297, 140215654037360])
Hence, you have two choices: initilize an empty array with length 0 then append. NOTE: as @hpaulj pointed out, you need to set some array to be equal to the array returned by np.append() i.e.
>>> a = np.array([],dtype = int)
>>> a = np.append(a,2)
>>> a = np.append(a,1)
>>> a = np.append(a,3)
>>> a = np.append(a,5)
>>> a
array([2, 1, 3, 5])
Or you can initialize by np.empty() but then you have to use up all the cells that you initialized first before appending. i.e.
>>> a = np.empty(3,dtype = np.int)
>>> a[0] = 2
>>> a[1] = 1
>>> a[2] = 5
>>> a = np.append(a,3)
>>> a
array([2, 1, 5, 3])
a[I]=n.dot...; that is assign a new value each preallocated element ofa.