[Numpy-discussion] alternative mechanism for initializing an array
Keith Goodman
kwgoodman at gmail.com
Thu Jul 16 15:09:03 EDT 2009
On Thu, Jul 16, 2009 at 11:43 AM, Phillip M.
Feldman<pfeldman at verizon.net> wrote:
> numpy.array understands
>
> V= array([[1,2,3,4],[4,3,2,1]])
>
> but not
>
> V= array([1,2,3,4],[4,3,2,1])
>
> It would be more convenient if it could handle either form.
You could do something like this:
def myarray(*args):
return np.array([z for z in args])
or
def myarray(*args, **kwargs):
return np.array([z for z in args], **kwargs)
Then
>> myarray([1,2,3], [4,5,6])
array([[1, 2, 3],
[4, 5, 6]])
>> myarray([1,2,3], [4,5,6], dtype=np.float64)
array([[ 1., 2., 3.],
[ 4., 5., 6.]])
More information about the NumPy-Discussion
mailing list