Hi, the doc-string of concatentate is pretty short: numpy.concatenate? Docstring: concatenate((a1,a2,...),axis=None). Would the following be better: """ concatenate((a1, a2,...), axis=None) joins the tuple `(a1, a2, ...)` of sequences (or arrays) into a single numpy array. Example:: print concatenate( ([0,1,2], [5,6,7])) """ ((The ``(or arrays)`` could be omitted if sequences include array by default, though it might not be obvious to beginners ...)) I was also tempted to suggest a dtype argument, concatenate( ([0,1,2], [5,6,7]), dtype=numpy.Float) but I am not sure if that would be a good idea ... Best, Arnd
Arnd Baecker <arnd.baecker@web.de> writes:
Hi,
the doc-string of concatentate is pretty short:
numpy.concatenate? Docstring: concatenate((a1,a2,...),axis=None).
Would the following be better: """ concatenate((a1, a2,...), axis=None) joins the tuple `(a1, a2, ...)` of sequences (or arrays) into a single numpy array.
Example::
print concatenate( ([0,1,2], [5,6,7])) """
((The ``(or arrays)`` could be omitted if sequences include array by default, though it might not be obvious to beginners ...))
Here's what I just checked in: concatenate((a1, a2, ...), axis=None) joins arrays together The tuple of sequences (a1, a2, ...) are joined along the given axis (default is the first one) into a single numpy array. Example: >>> concatenate( ([0,1,2], [5,6,7]) ) array([0, 1, 2, 5, 6, 7])
I was also tempted to suggest a dtype argument, concatenate( ([0,1,2], [5,6,7]), dtype=numpy.Float) but I am not sure if that would be a good idea ...
Well, that would require more code, so I didn't do it :-) -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |cookedm@physics.mcmaster.ca
On Wed, 26 Apr 2006, David M. Cooke wrote:
Arnd Baecker <arnd.baecker@web.de> writes:
Hi,
the doc-string of concatentate is pretty short:
numpy.concatenate? Docstring: concatenate((a1,a2,...),axis=None).
Would the following be better: """ concatenate((a1, a2,...), axis=None) joins the tuple `(a1, a2, ...)` of sequences (or arrays) into a single numpy array.
Example::
print concatenate( ([0,1,2], [5,6,7])) """
((The ``(or arrays)`` could be omitted if sequences include array by default, though it might not be obvious to beginners ...))
Here's what I just checked in:
concatenate((a1, a2, ...), axis=None) joins arrays together
The tuple of sequences (a1, a2, ...) are joined along the given axis (default is the first one) into a single numpy array.
Example:
>>> concatenate( ([0,1,2], [5,6,7]) ) array([0, 1, 2, 5, 6, 7])
Great - many thanks!! There are some further routines which might benefit from some more explanation/examples - so if you don't mind I will try to suggest some additions (I could check them in directly, I think, but as I am not a native speaker I feel better to post them here for review/improvement).
I was also tempted to suggest a dtype argument, concatenate( ([0,1,2], [5,6,7]), dtype=numpy.Float) but I am not sure if that would be a good idea ...
Well, that would require more code, so I didn't do it :-)
;-) It might also be problematic, when one of the sequence elements would not fit into the output type. Best, Arnd
On 4/26/06, David M. Cooke <cookedm@physics.mcmaster.ca> wrote:
.... Here's what I just checked in:
concatenate((a1, a2, ...), axis=None) joins arrays together
The tuple of sequences (a1, a2, ...) are joined along the given axis (default is the first one) into a single numpy array.
Example:
>>> concatenate( ([0,1,2], [5,6,7]) ) array([0, 1, 2, 5, 6, 7])
The first argument does not have to be a tuple:
print concatenate([[0,1,2], [5,6,7]]) [0 1 2 5 6 7]
but the docstring is probably ok given that the alternative is "sequence of sequences" ...
On Wed, 26 Apr 2006, Sasha wrote:
On 4/26/06, David M. Cooke <cookedm@physics.mcmaster.ca> wrote:
.... Here's what I just checked in:
concatenate((a1, a2, ...), axis=None) joins arrays together
The tuple of sequences (a1, a2, ...) are joined along the given axis (default is the first one) into a single numpy array.
Example:
>>> concatenate( ([0,1,2], [5,6,7]) ) array([0, 1, 2, 5, 6, 7])
The first argument does not have to be a tuple:
print concatenate([[0,1,2], [5,6,7]]) [0 1 2 5 6 7]
but the docstring is probably ok given that the alternative is "sequence of sequences" ...
Seems to be the usual problem of either being slightly unprecise but understandable or legally correct but impossible to understand (in particular for beginners). What about changing the example to: """ Examples:
concatenate(([0, 1, 2], [5, 6, 7])) array([0, 1, 2, 5, 6, 7])
concatenate([[0, 1, 2], [5, 6, 7]]) array([0, 1, 2, 5, 6, 7])
z = arange(5) concatenate(([0, 1, 2], [5, 6, 7], z)) array([0, 1, 2, 5, 6, 7, 0, 1, 2, 3, 4]) """
Best, Arnd
David M. Cooke wrote:
Here's what I just checked in:
concatenate((a1, a2, ...), axis=None) joins arrays together
The tuple of sequences (a1, a2, ...) are joined along the given axis (default is the first one) into a single numpy array.
Example:
>>> concatenate( ([0,1,2], [5,6,7]) ) array([0, 1, 2, 5, 6, 7])
While we're at it, why not an example of how the axis argument works:
concatenate( (ones((1,3)), zeros((1,3))) ) array([[1, 1, 1], [0, 0, 0]])
concatenate( (ones((1,3)), zeros((1,3))), axis = 0 ) array([[1, 1, 1], [0, 0, 0]]) concatenate( (ones((1,3)), zeros((1,3))), axis = 1 ) array([[1, 1, 1, 0, 0, 0]])
I'm not sure I like this example, but it's a easy way to do a one liner. -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@noaa.gov
participants (4)
-
Arnd Baecker
-
Christopher Barker
-
cookedm@physics.mcmaster.ca
-
Sasha