[SciPy-User] re[SciPy-user] moving for loops...
Thu Jun 17 11:33:27 CDT 2010
Well, there is numpy.tile() that can replicate a numpy array multiple times
in various dimensions, but I have to wonder if you need to step back and
think about why your dimensions aren't matching up. If you are pulling in
data where one of the dimensions has a length of 90, but the corresponding
array that denotes that dimension (timesteps) has a length of 30, then I
have to wonder if there needs to be some rethinking of the overall design.
On Thu, Jun 17, 2010 at 11:02 AM, mdekauwe <firstname.lastname@example.org> wrote:
> So what happens if I need to extend in two directions at once? So for
> 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,
> 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:
> Sent from the Scipy-User mailing list archive at Nabble.com.
> SciPy-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User