[Numpy-discussion] speed of atleast_1d and friends

Keith Goodman kwgoodman@gmail....
Tue Aug 4 09:37:03 CDT 2009

On Tue, Aug 4, 2009 at 4:23 AM, Mark Bakker<markbak@gmail.com> wrote:
> Hello all,
> I am making a lot of use of atleast_1d and atleast_2d in my routines.
> Does anybody know whether this will slow down my code significantly?
> Thanks,
> Mark

Here's atleast_1d:

def atleast_1d(*arys):
    res = []
    for ary in arys:
    if len(res) == 1:
        return res[0]
        return res

If you only pass in on array at a time, that reduces to:

def myatleast_1d(ary):
    return array(ary, copy=False, subok=True, ndmin=1)

That might save some time.

I'm always amazed at the solutions people come up with on this list.
So if you send an example, someone might be able to get rid of the
need for atleast_1d.

More information about the NumPy-Discussion mailing list