From: Paul F D. <pa...@pf...> - 2002-09-13 21:06:10
|
This is a perfect example of why the thing is so annoying. > -----Original Message----- > From: num...@li... > [mailto:num...@li...] On > Behalf Of eric jones > Sent: Friday, September 13, 2002 1:44 PM > To: 'Tim Hochberg'; num...@li... > Subject: 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: num...@li... [mailto:numpy- > > dis...@li...] On Behalf Of Tim Hochberg > > Sent: Friday, September 13, 2002 3:18 PM > > To: num...@li... > > 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 Num...@li... > > 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 > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |