Re: [Numpy-discussion] A minor clarification no why count_nonzero is faster for boolean arrays

2015-12-17 Thread Raghav R V
Thanks a lot everyone! I am time and again amazed by how optimized numpy is! Hats off to you guys! R On Thu, Dec 17, 2015 at 11:02 PM, Jaime Fernández del Río < jaime.f...@gmail.com> wrote: > On Thu, Dec 17, 2015 at 7:37 PM, CJ Carey > wrote: > >> I believe this line is the reason: >> >> https

[Numpy-discussion] A minor clarification no why count_nonzero is faster for boolean arrays

2015-12-17 Thread Raghav R V
I was just playing with `count_nonzero` and found it to be significantly faster for boolean arrays compared to integer arrays >>> a = np.random.randint(0, 2, (100, 5)) >>> a_bool = a.astype(bool) >>> %timeit np.sum(a) 10 loops, best of 3: 5.64 µs per loop >>> %timeit np.