On Tue, 22 Feb 2022, 6:53 am Stefan van der Walt, <stef...@berkeley.edu> wrote:
> On Mon, Feb 21, 2022, at 20:56, Juan Nunez-Iglesias wrote: > > > the > > latter would seem consistent with the "principle of least surprise" when > moving from a typed language to > > NumPy work perhaps, though arguably slightly less user-friendly if > naively doing some operations with > > a less formal view of typing (new Python user messing around with NumPy?) > > fwiw, my rationale here is that many (most?) beginners will eventually > become intermediate-to-advanced, at which point purity becomes increasingly > important. It is often easier to explain a "pure" principle to a beginner > than it is to navigate around magic behaviour as an expert. At scikit-image > tutorials we often begin by having the users overflow a uint8 image, then > we explain why that's the case and how to work around it. > > > Just to play a bit of devil's advocate here, I'd have to say that most > people will not expect > > x[0] + 200 > > To often yield a number less than 200! > > I think uint8's are especially problematic because they overflow so > quickly (you won't easily run into the same behavior with uint16 and > higher). Of course, there is no way to pretend that NumPy integers are > Python integers, but by changing the casting table for uint8 a bit we may > be able to avoid many common errors. > But sometimes you actually want the overflow, for bit operations. Probably not with an int8, I believe that is UB in C. /David
_______________________________________________ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com