[Numpy-discussion] Need to eliminate a nested loop

2011-05-10 Thread Elfnor
Hi The following code produces the desired result but has a slow triple loop iterating over the matrix multiplication. I'm sure it can be eliminated with a neat indexing trick but I can't figure out how. Any suggestions please? - import numpy #define domain of

[Numpy-discussion] rollaxis and reshape

2008-12-10 Thread Elfnor
Hi I'm trying to split an array into two pieces and have the two pieces in a new dimension. Here it is in code, because that's hard to explain in words. data.shape (4, 50, 3) new_data = numpy.zeros((2, 4, 25, 3)) new_data[0,...] = data[:,:25,:] new_data[1,...] = data[:,25:,:] new_data.shape

[Numpy-discussion] Apply a function to an array elementwise

2008-12-03 Thread Elfnor
Hi I want to apply a function (myfunc which takes and returns a scalar) to each element in a multi-dimensioned array (data): I can do this: newdata = numpy.array([myfunc(d) for d in data.flat]).reshape(data.shape) But I'm wondering if there's a faster more numpy way. I've looked at the

[Numpy-discussion] assign a variable to each column of an array

2007-12-16 Thread elfnor
Is there a more concise way of assigning a variable to each column of an array? This works x,y,z = X[:,0],X[:,1],X[:,2] but seems clumsy. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org