RE: [Numpy-discussion] rank-0 arrays
by eric jones other posts by this author
Sep 13 2002 8:43PM messages near this date
RE: [Numpy-discussion] rank-0 arrays
|
Re: [Numpy-discussion] rank-0 arrays
Hey Tim,
Here is a short summary:
Reductions and indexing return different types based on the number of
dimensions of the input array:
> >> b = sum(a)
> >> l = len(b) # or whatever
This code works happily if "a" is 2 or more dimensions, but will fail if
it is 1d because the sum(a) will return a scalar in this case. To write
generic code, you have to put an if/else statement in to check whether b
is a scalar or an array:
> >> b = sum(a)
> >> if type(b) is ArrayType:
... l = len(b)
... else:
... l = 1 # or whatever you need
or less verbose but still unpleasant:
> >> b = asarray(sum(a))
> >> l = len(b)
eric
> -----Original Message-----
> From: numpy-discussion-admin@[...].net [mailto:numpy-
> discussion-admin@[...].net] On Behalf Of Tim Hochberg
> Sent: Friday, September 13, 2002 3:18 PM
> To: numpy-discussion@[...].net
> Subject: Re: [Numpy-discussion] rank-0 arrays
>
>
>
>
> [Perry wrote about Travis's proposal]
>
> > refresh my memory about how this proposal would work. I've heard
> > proposals to add new types to Python itself, but that seems out of
> > the question. Are you talking about adding new scalar types as
> > module? E.g.
> [snip]
> > In any case, doesn't this still have the problem that Eric
complained
> > about, having to test for whether a result is an array or a scalar
> > (which was one of the drivers to produce rank-0 results).
>
> Hi Perry,
>
> I like Travis's proposal the best of those I've seen so far, but I
don't
> recall the details of Eric's problem. Could you refresh us as to the
> basics
> of it?.
>
> -tim
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@[...].net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Thread:
Perry Greenfield
Travis Oliphant
Pearu Peterson
Konrad Hinsen
Perry Greenfield
Todd Miller
Pearu Peterson
Konrad Hinsen
Travis Oliphant
Konrad Hinsen
Perry Greenfield
Travis Oliphant
Tim Hochberg
Chris Barker
Konrad Hinsen
Perry Greenfield
Travis Oliphant
Pearu Peterson
Tim Hochberg
Perry Greenfield
Konrad Hinsen
Perry Greenfield
eric jones
Konrad Hinsen
eric jones
Konrad Hinsen
Tim Hochberg
Tim Hochberg
Paul F Dubois
Scott Gilbert
Konrad Hinsen
|