[Numpy-discussion] ufuncs on funny strides; also isnan, isfinite, etc on a variety of dtypes

M Trumpis mtrumpis@berkeley....
Thu Apr 1 14:38:27 CDT 2010


On Thu, Apr 1, 2010 at 11:53 AM, Warren Weckesser
<warren.weckesser@enthought.com> wrote:
> M Trumpis wrote:
>> Hi all,
>>
>> <snip>
>>
>> And a last mini question, it doesn't appear that any() is doing short
>> circuit evaluation. It runs in appx the same time whether an array is
>> sparsely nonzero, fully zero, or fully nonzero.
>>
>>
>
> That's not what I see.  Here's an example that shows the a linear
> increase in time:
>
> In [112]: x = np.zeros((1000,1000), dtype=bool)
>
> In [113]: y = np.zeros((1000,1000), dtype=bool)
>
> In [114]: z = np.zeros((1000,1000), dtype=bool)
>
> In [115]: x[0,0] = 1
>
> In [116]: y[500,0] = 1
>
> In [117]: z[-1,-1] = 1
>
> In [118]: %timeit x.any()
> 100000 loops, best of 3: 4 us per loop
>
> In [119]: %timeit y.any()
> 1000 loops, best of 3: 566 us per loop
>
> In [120]: %timeit z.any()
> 1000 loops, best of 3: 1.13 ms per loop
>

Yes, you're quite right. I was confused and abusing the usage a little
by calling any() on non-boolean arrays. It appears in that case
there's some uniform overhead that can swamp the boolean any()

Mike

>
> Warren
>
>> Kind regards,
>> Mike
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list