[Numpy-discussion] Re: What am I missing about concatenate?

Christopher Barker Chris.Barker at noaa.gov
Thu Jun 1 12:14:01 CDT 2006


Thanks all,


Robert Kern wrote:
> Look at vstack() (and also its friends hstack(), dstack() and column_stack() for
> completeness).

I like this, but need to keep Numeric/numarray compatibility for the 
moment -- I think, I've just sent out a query to my users.



Tim Hochberg wrote:
> If you are using real arrays, use newaxis:
> 
>     >>> a
>    array([0, 1, 2])
>     >>> b
>    array([3, 4, 5])
>     >>> concatenate([a[newaxis], b[newaxis]], 0)
>    array([[0, 1, 2],
>           [3, 4, 5]])

I like this, but again, not in Numeric -- I really need to dump that as 
soon as I can!

> hate newaxis, wrap the arrays in [] to give them an extra dimension. 
> This tends to look nicer, but I suspect has poorer performance than 
> above (haven't timed it though):
> 
>     >>> concatenate([[a], [b]], 0)
>    array([[0, 1, 2],
>           [3, 4, 5]])

Lovely. much cleaner.

By they way, wouldn't wrapping in a tuple, be slightly better, 
performance-wise (I know, probably negligible, but I always feel that I 
should use a tuple when I don't need mutability)

-thanks,

-chris




-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the Numpy-discussion mailing list