This is beautiful! Thank you Pauli. On Sat, Dec 4, 2010 at 7:16 PM, Pauli Virtanen <[email protected]> wrote:
> On Sat, 04 Dec 2010 19:00:43 +0000, Eleftherios Garyfallidis wrote: > [clip] > > I am using ndindex and then a for loop. Is there a better/faster way? > > Yes: > > import numpy as np > from numpy import newaxis > > x = np.zeros((200, 200, 200, 3)) > x[...,0] = np.arange(200)[:,newaxis,newaxis] > x[...,1] = np.arange(200)[newaxis,:,newaxis] > x[...,2] = np.arange(200)[newaxis,newaxis,:] > x[1,3,2] > # -> array([ 1., 3., 2.]) > > Depending on what you use this array for, it's possible that you can > avoid constructing it (and use broadcasting etc. instead). > > -- > Pauli Virtanen > > _______________________________________________ > NumPy-Discussion mailing list > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion >
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
