[Numpy-discussion] Set values of a matrix within a specified range to zero

Ryan May rmay31 at gmail.com
Tue Mar 30 17:57:39 EDT 2010

On Tue, Mar 30, 2010 at 3:40 PM, Robert Kern <robert.kern at gmail.com> wrote:
> On Tue, Mar 30, 2010 at 16:35, Ryan May <rmay31 at gmail.com> wrote:
>> On Tue, Mar 30, 2010 at 3:16 PM, Friedrich Romstedt
>> <friedrichromstedt at gmail.com> wrote:
>>> x *= ((x <= 23) | (x >= 45))  .
>> Interesting. In an ideal world, I'd love to see why exactly that is,
>> because I don't think multiplication should be faster than a boolean
>> op.
> Branch prediction failures are really costly in modern CPUs.
> http://en.wikipedia.org/wiki/Branch_prediction

That makes sense.

I still maintain that for 95% of code, easy to understand code is more
important than performance differences due to branch misprediction.
(And more importantly, we don't want to be teaching new users to code
like that from the beginning.)


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

More information about the NumPy-Discussion mailing list