[SciPy-User] re[SciPy-user] moving for loops...

mdekauwe mdekauwe@gmail....
Thu Jun 17 11:02:19 CDT 2010

So what happens if I need to extend in two directions at once? So for example
I have 2 arrays...

timesteps = np.arange(30)
y which has dimensions 90, 3, where each row has values of say 1.2, 3.4,

then I have some function I call "func", where the arguments are timesteps
and each of the rows of y, e.g. 

func(x, y[0,:])

However if I wanted to carry out this step for each of the rows (90) of y, I
can't seem to broadcast this correctly.

tmp = func(timesteps[:,np.newaxis], y)

I can see why, as this will only stretch timesteps in one direction so that
it becomes (30, 3), so is there a nice way to stretch the rows as well? I
thought perhaps I needed to reshape timesteps first, but I didn't seem to
solve it that way either.

Incase none of this made sense... my original loop version

tmp = np.zeros((90, 30))
for i in xrange(len(y)):
    tmp[i,:] = func(timsteps, y[i])

I have the feeling I am missing something very obvious here! Thanks!

View this message in context: http://old.nabble.com/removing-for-loops...-tp28633477p28916343.html
Sent from the Scipy-User mailing list archive at Nabble.com.

More information about the SciPy-User mailing list