[Numpy-discussion] alternative mechanism for initializing an array

Phillip M. Feldman pfeldman@verizon....
Fri Jul 17 00:36:40 CDT 2009


I think that I finally figured it out.  See code below.

Phillip


*** Start of myarray.py ***
import numpy

def array(*args, **kwargs):
    """This function acts as an interface to numpy.array, accepting
    multi-row matrices with or without an outer set of enclosing brackets.
    Usage examples:

    In [1]: from myarray import array
    In [2]: x=array([1,2,3],[4,5,6],dtype=int)
    In [3]: x/2
    Out[3]:
    array([[0, 1, 1],
           [2, 2, 3]])

    Dr. Phillip M. Feldman   16 July 2009"""

    args1= []
    args2= []
    for arg in args:
       if isinstance(arg,list):
          args1.append(arg)
       else:
          args2.append(arg)
    if len(args1)==1: args1= args1[0]
    if len(args2)==1: args2= args2[0]

    if len(args2):
       return numpy.array(args1, args2, **kwargs)
    else:
       return numpy.array(args1, **kwargs)
*** End of myarray.py ***

From: Keith Goodman <kwgoodman <at> gmail.com>
Subject: Re: alternative mechanism for initializing an array
<http://news.gmane.org/find-root.php?message_id=%3cf4f93d420907161357m99aefa3s83ae1ff043abb83e%40mail.gmail.com%3e>
Newsgroups: gmane.comp.python.numeric.general
<http://news.gmane.org/gmane.comp.python.numeric.general>
Date: 2009-07-16 20:57:18 GMT (4 hours and 29 minutes ago)


More information about the NumPy-Discussion mailing list