[Python-ideas] [Python-ideos] Dedicated overloadable boolean operators
Nick Coghlan
ncoghlan at gmail.com
Thu Nov 26 00:44:17 EST 2015
On 26 November 2015 at 09:58, Chris Barker - NOAA Federal
<chris.barker at noaa.gov> wrote:
>> While I'm still largely of the view that introducing additional
>> operators would make things more confusing rather than less,
>
> Well, almost by definition, more stuff to understand is more confusing
> for beginners.
>
>> there needs to be a fairly
>> concise answer to "What are these operators for?".
>
> I don't think "they are for doing logical operations on each of the
> elements in a sequence, rather than the sequence as a whole", along
> with an example or two is particularly challenging.
>
> In fact, much less so than the Bitwise operators, or matrix
> multiplication, which require a bit of domain knowledge, as you say.
> But those aren't a big problem either: "if you don't know what it
> means, you probably don't need it"
Right, that's why I think "elementwise logical operators (which may
potentially be useful for other things)" is an idea that has some hope
of avoiding creating new barriers to learning:
* if "elementwise" doesn't mean anything to you, and no library you're
using mentions them in its documentation, you can ignore them
* for folks that do know what it means, "elementwise" is evocative of
the relevant semantics for at least the data analysis use case
> But as for general element-wise operators:
I wasn't suggesting those - just element-wise logical operators. In
terms of scoping the use case: bitwise and/or/not work fine for
manipulating existing boolean masks, and converting a single matrix to
a boolean mask involves apply an elementwise function, not elementwise
logical operations.
So elementwise logical operators would presumably be aimed at *data
merging* problems - creating a combined matrix where some values are
taken from matrix A and others from matrix B, based on the truthiness
of those values. I'm not enough of a data analyst to know how common
that problem is, or whether it might be better served by a higher
level "replace_elements" operation that accepts a base array, a
replacement array, and a boolean mask saying which values to replace.
Regards,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list