[Numpy-discussion] Re: Bypassing a[2].item()?
Travis Oliphant
oliphant at ee.byu.edu
Thu Apr 20 20:16:02 EDT 2006
Robert Kern wrote:
>Ryan Gutenkunst wrote:
>
>
>>On Apr 20, 2006, at 5:18 PM, Robert Kern wrote:
>>
>>
>>
>>>Ryan Gutenkunst wrote:
>>>
>>>
>
>
>
>>>>2) If not, is it possible to get a "pure" scalar directly from an array
>>>>in one function call?
>>>>
>>>>
>>>float(x[0]) seems to be faster on my PowerBook.
>>>
>>>
>>It's faster for me, too, but float(x[0]) is still much slower than using
>>Numeric where x[0] suffices. I guess I'll just have to warn my users
>>away from the new scipy until numpy 0.9.8 comes out and scalar math is
>>sped up.
>>
>>
>
>For that matter, a plain "x[0]" seems to be about 3x faster with Numeric than numpy.
>
>
>
We are already special-casing the integer select code but could
special-case the getitem code so that if nd==1 a faster construction is
used. I think right now a 0-dim array is being created only to get
destroyed later on return. Please add a ticket as this extremely
common operation should be made as fast as possible.
This is a little tricky because array_big_item is called in a few places
and is expected to return an array. If it returns a scalar in those
places segfaults can occur. Either checks need to be made in each of
those cases or the special-casing needs to be in array_big_item_nice.
I'm not sure which I prefer....
-Travis
More information about the NumPy-Discussion
mailing list