How should I use Numpy's vstack method?

vstacking again and again is not good, because it copies the whole arrays.

Create a normal Python list, .append to it and then pass it whole to np.vstack to create a new array once.

stokes_list = []
for i in xrange(numrows):
    ...
    stokes_line = ...
    stokes_list.append(stokes_line)

big_stokes = np.vstack(stokes_list)

You already know the final size of the stokes_list array since you know numrows. So it seems you don't need to grow an array (which is very inefficient). You can simply assign the correct row at each iteration. Simply replace your last line by :

stokes_list[i] = stokes_line

By the way, about your non-working line I think you meant :

stokes_list = np.vstack((stokes_list, stokes_line))

where you're replacing stokes_list by its new value.

Tags:

Python

Numpy