[Numpy-discussion] Wrong behavior of atleast_3d?
Yannick Copin
y.copin at ipnl.in2p3.fr
Wed Oct 8 08:21:04 EDT 2008
Hi,
I wonder if there's a "behavior bug" in atleast_3d, with respect to
atleast_2d. In atleast_2d, the results on a 1D-array or on a single-element
list of 1D-arrays are the same:
In [22]: atleast_2d(arange(3)).shape
Out[22]: (1, 3)
In [23]: atleast_2d([arange(3),]).shape
Out[23]: (1, 3)
On the contrary, with atleast_3d, the results differ between a 2D-array and a
single-element list of 2D-arrays:
In [24]: atleast_3d(randn(3,3)).shape
Out[24]: (3, 3, 1)
In [25]: atleast_3d([randn(3,3),]).shape
Out[25]: (1, 3, 3)
Wouldn't it be more logical wrt atleast_2d that atleast_3d(randn(3,3)) return
an array of shape (1,3,3)? (even though the docstring makes it clear that it
*will* return a (3,3,1)-array).
I mostly use atleast_nd to be able to iterate over input arrays without having
to know if it's a single array, or a list of arrays. For that, at_least2d has
the correct behavior, but not atleast_3d.
Cheers.
--
.~. Yannick COPIN (o:>* Doctus cum libro
/V\ Institut de physique nucleaire de Lyon (IN2P3 - France)
// \\ Tel: (33/0) 472 431 968 AIM: YnCopin ICQ: 236931013
/( )\ http://snovae.in2p3.fr/ycopin/
^`~'^
More information about the NumPy-Discussion
mailing list