[SciPy-user] filling array without loop...

Anne Archibald peridot.faceted@gmail....
Mon Apr 23 11:17:34 CDT 2007

On 23/04/07, fred <fredmfp@gmail.com> wrote:
> Anne Archibald a écrit :
> > Um, first of all, what are you trying to accomplish with all those
> > hstack()s?
> >
> Because you told me so ;-) in your first answer.
> So, if it is not right, what do you mean by "using one of numpy's
> stacking functions to put the matrices together..." ?

Well, I see your problem in two parts: (1) build an array of shape
(7,nx,ny,nz), then (2) flatten it enough to make VTK happy. Step (1)
is most easily accomplished by making a list of 7 arrays of shape
(nx,ny,nz) then putting them together along a new axis. Making the
arrays is no problem, you just use broadcasting. Step (2). putting a
list of arrays together into one array along a new axis you can do
with array(), or you could use one of the stacking functions. You only
have to do that once, so I'm not clear on why you use so many
hstack()s. I'd take a look at the Numpy Example List; it looks like
none of the available functions do quite what you want, although a
combination of [...,newaxis] and concatenate might be all right.

Since all your hstack()s and vstack()s aren't doing anything useful,
I'd get rid of them - at the least they have to make copies of their


More information about the SciPy-user mailing list