What I am doing: generating a series of long 1D arrays.
What I want to do: append/concatentate/vstack/? these into a 2D array, then save the rows as columns in a csv file.
The following works, but it's not elegant:
rlist=[] # create empty list
for i in range(nnn) # nnn is typically 2000
(calculate an array "r")
rlist.append(r) # append f.p. array to rlist
rarr = array(rlist) # turn it back into array so I can transpose
numpy.savetxt('test.csv',rarr.T,delimiter=',') # save rows as columns in csv file
Is there a more elegant or pythonesque way to do it?
numpy.vstackand a transpose -- But in the end, it will be the same number of lines of code and you'll either be growing the same array at every iteration of the loop (which is likely to be inefficient) or waiting until the end to stack them all together (which is what you're doing now). I don't see much difference ...