[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.


*** 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
    array([[0, 1, 1],
           [2, 2, 3]])

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

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

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

From: Keith Goodman <kwgoodman <at> gmail.com>
Subject: Re: alternative mechanism for initializing an array
Newsgroups: 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