I simply want to create an (n,1) array from the int values (dist) in my for a loop.
For now, I only have a succession of int values, since I’m printing the "dist" value in each iteration.
How do I incorporate each dist into an array (in this case only an n-vector), so that array[i] is the dist value from the ith iteration of the for loop?
I know it must be really simple, I’m only starting out on NumPy. I’ve tried out with insert, append, doesn’t seem to work. My distmatrix initialized in the beginning is not used…
here is the code for now:
distmat=np.zeros((len(CoordNodesRad[:,0]),1),int) lat = CoordNodesRad[:,0] lng = CoordNodesRad[:,1] for i in range(len(CoordNodesRad[:,0])): dist = distanceGPS(depot, depot, lat[i], lng[i]) #print(int(dist)) #distmat=np.append(distmat,dist,axis=0) print(dist) distmat=np.insert(dist,i,dist) print(distmat)
thanks for the help
Source: Python Questions