# [Numpy-discussion] Rationale for atleast_3d

Robert Kern robert.kern at gmail.com
Fri Sep 22 16:14:47 CDT 2006

```Travis Oliphant wrote:
> Bill Baxter wrote:
>
>> 26 weeks, 4 days, 2 hours and 9 minutes ago, Zdeněk Hurák asked why
>> atleast_3d acts the way it does:
>> http://article.gmane.org/gmane.comp.python.numeric.general/4382/match=atleast+3d
>>
>> He doesn't seem to have gotten any answers.  And now I'm wondering the
>> same thing.  Anyone have any idea?
>>
> This function came from scipy and was written by somebody at Enthought.
> I was hoping they would respond.

That would have either been from Eric or Travis V way back in the day. Both are
out of the office today. The "3D arrays as stacks of 2D arrays" is probably as
good an explanation as any. Much of Numeric (e.g. the axis dot() reduces over)
was predicated on that kind of logic. There is probably some kind of consistency
argument with dstack() and atleast_2d(), i.e.

In [46]: a = arange(5)

In [47]: atleast_3d(a)
Out[47]:
array([[[0],
[1],
[2],
[3],
[4]]])

In [48]: dstack([a, a])
Out[48]:
array([[[0, 0],
[1, 1],
[2, 2],
[3, 3],
[4, 4]]])

In [49]: dstack(map(atleast_2d, [a, a]))
Out[49]:
array([[[0, 0],
[1, 1],
[2, 2],
[3, 3],
[4, 4]]])

In [50]: dstack(map(atleast_3d, [a, a]))
Out[50]:
array([[[0, 0],
[1, 1],
[2, 2],
[3, 3],
[4, 4]]])

That's the problem with consistency arguments; there are so many things one
could be consistent with!

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma