[Numpy-discussion] Rationale behind behaviour of atleast_3d in Numpy

Zdeněk Hurák hurak at control.felk.cvut.cz
Mon Mar 20 02:37:01 CST 2006


As a newcommer, I am trying not only to learn to use Numpy, but also to
understand it. I think I need some help with function atleast_3d. When
applied to 2d array, its behaviour is different then when applied to 1d
array (it is a documented feature):

a = array([1,2,3])
A = array([[1,2,3],[4,5,6]])

a3d = atleast_3d(a)
print a3d.shape
---> (1, 3, 1)

A3d = atleast_3d(A)
print A3d.shape
---> (2, 3, 1)

What is the rationale behind this in my opinion unintuitive inconsistency? I
especially don't understand the behaviour for 1d arrays. But even with 2d
arrays, I am inclined to think (with my beginner-level of mastering Python
and Numpy) that a more natural result of shape function would be (1,2,3).

Thank you very much for some explanation,
Zdenek Hurak 

More information about the Numpy-discussion mailing list