Fill in numbers in a numpy array in sets of 1024

Viewed 377

I have a large numpy array with increasing elements as follows

A = [512,2560,3584,5632,....]

Elements are always spaced at least 1024 apart

Let's say I need to transform that above array to the one below, where for each element of the original matrix A, I take a range of values from A[n] to A[n]+1024 (in steps of one) and those become the values of a new matrix as follows

A2 = [512,513,514,...,1535,2560,2561,2562,...3583,....]

The way I've set up the problem is to loop through the original matrix A, generate a range of values between A[0] and A[0]+1024 (for example), allocate them to a new array and so on. Code below. Convention is for A as the original seed matrix

seed = 0
A2 = np.empty(len(A)*1024,)
for ind in range(len(A)):
    A2[seed:seed+1024] = np.arange(A[ind],A[ind]+1024)
    seed = seed+1024;

I get the answer I need, but I'm wondering if that is the best way to do this. I'm a matlab user transitioning to using python and numpy, and I'm not used to optimizing numpy yet. I appreciate any help.

2 Answers
Related