[Numpy-discussion] floats as axis

josef.pktd at gmail.com josef.pktd at gmail.com
Sun Apr 25 10:54:26 EDT 2010


On Sun, Apr 25, 2010 at 10:45 AM, Keith Goodman <kwgoodman at gmail.com> wrote:
> On Sun, Apr 25, 2010 at 6:16 AM,  <josef.pktd at gmail.com> wrote:
>> (some) numpy functions take floats as valid axis argument. Is this a feature?
>>
>>>>> np.ones((2,3)).sum(1.2)
>> array([ 3.,  3.])
>>>>> np.ones((2,3)).sum(1.99)
>> array([ 3.,  3.])
>>
>>>>> np.mean((1.5,0.5))
>> 1.0
>>>>> np.mean(1.5,0.5)
>> 1.5
>>
>> Keith pointed out that scipy.stats.nanmean has a different behavior
>>
>>>>> stats.nanmean(np.ones((2,3)), axis= 1.2)
>> Traceback (most recent call last):
>> <...>
>> TypeError: tuple indices must be integers
>
> It fails on axis=0.0 and axis=1.0 too. Those are probably more common
> values and less likely to be an error.

I wouldn't trust floating 1.0 or 0.0 either

>>> np.ones((2,3)).sum(1.+1e-16)
array([ 3.,  3.])
>>> np.ones((2,3)).sum(1.-1e-16)
array([ 2.,  2.,  2.])

Josef

>
>> see: http://projects.scipy.org/scipy/ticket/1165
>>
>> What's the preferred behavior?
>>
>> Josef
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list