0

So here is what I try to do,

N=1000
x=np.arange(0,1,1./float(len(N)))    
XX,YY=np.meshgrid(x,x)   

l=len(XX)
grid=np.array([ ([XX[i,i],YY[j,j],0. ]) for i in xrange(l) for j in xrange(l) ])

the numpy routine is rather fast but I need the grid to be in a different form and this takes quite long (I guess because of indexing the numpy array).

Thanks for any suggestions : )

Cheers

1
  • len(N) doesn't work by the way Commented Dec 11, 2012 at 11:57

2 Answers 2

3

Take advantage of broadcasting:

z = np.zeros([N, N, 3])
z[:,:,0] = x.reshape(-1,1)
z[:,:,1] = x
fast_grid = z.reshape(N*N, 3)

print np.all( grid == fast_grid ) 
True
Sign up to request clarification or add additional context in comments.

Comments

0

You could do something like:

grid = np.mgrid[:N, :N, :1]
grid = grid.T.reshape(-1, 3)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.