[Python-ideas] Vectorization [was Re: Add list.join() please]
David Mertz
mertz at gnosis.cx
Sun Feb 3 15:34:26 EST 2019
On Sun, Feb 3, 2019 at 3:16 PM Ronald Oussoren <ronaldoussoren at mac.com>
wrote:
> The @ operator is meant for matrix multiplication (see PEP 465) and is
> already used for that in NumPy. IMHO just that is a good enough reason for
> not using @ as an elementwise application operator (ignoring if having an
> such an operator is a good idea in the first place).
>
Co-opting operators is pretty common in Python. For example, the
`.__div__()` operator spelled '/' is most often used for some kind of
numeric division. Some variations on that, for example vectorized in
NumPy. And different numeric types operate a bit differently. The name of
the magic method obvious suggests division.
And yet, in the standard library we have pathlib which we can use like this
(from the module documentation):
>>> p = Path('/etc')>>> q = p / 'init.d' / 'reboot'
That use is reasonable and iconic, even if it is nothing like division.
The `.__mod__()` operator spelled '%' means something very different in
relation to a float or int object versus a string object. I.e. modulo
division versus string interpolation.
I've even seen documentation of some library that coopts `.__matmul__()` to
do something with email addresses. It's not a library I use, just
something I once saw the documentation on, so I'm not certain of details.
But you can imagine that e.g. :
email = user @ domain
Could be helpful and reasonable (exact behavior and purpose could vary, but
it's "something about email" iconically).
In other words, I'm not opposed to using the @ operator in my
stringpy.Vector class out of purity about the meaning of operators. I just
am not convinced that it actually adds anything that is not easier without
it.
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190203/1dcce096/attachment.html>
More information about the Python-ideas
mailing list