[Numpy-discussion] Avoiding array-scalar arithmetic?

Ryan Gutenkunst rng7 at cornell.edu
Thu Sep 14 17:15:15 CDT 2006


Hi Travis,

Travis Oliphant wrote:
> Ryan Gutenkunst wrote:
>> I notice that numpy_array.item() will give me the first element as a 
>> normal scalar. Would it be possible for numpy_array.item(N) to return 
>> the Nth element of the array as a normal scalar?
>>   
> Now this is an interesting idea.  It would allow you to by-pass the 
> slow-indexing as well as the array scalar computation should you desire 
> it.  I like it and am going to add it unless there are convincing 
> objections.
> 
> -Travis

Thanks for the quick response, but either there's a bug, or I'm using 
things wrong. It appears to work to work in the N-D case, but not 1-D. I 
looked at the change you made, but my grasp of the C-API is too weak to 
isolate the problem.

 >>> import numpy
 >>> numpy.__version__
'1.0rc1.dev3154'
 >>> a = numpy.array([[1.0, 2.0], [3.0, 4.0]])
 >>> a.item(1,1)
4.0
 >>> a = numpy.array([1.0, 2.0])
 >>> a.item(0)
1.0
 >>> a.item(1)
1.7765824089018436e-307
 >>> a.item((1,))
1.7765824089018436e-307


Thanks for your help,
Ryan

-- 
Ryan Gutenkunst               |
Cornell LASSP                 |       "It is not the mountain
                               |        we conquer but ourselves."
Clark 535 / (607)227-7914     |        -- Sir Edmund Hillary
AIM: JepettoRNG               |
          http://www.physics.cornell.edu/~rgutenkunst/





More information about the Numpy-discussion mailing list