[Numpy-discussion] Syntax Improvement for Array Transpose

Stephan Hoyer shoyer at gmail.com
Mon Jun 24 10:59:42 EDT 2019


On Sun, Jun 23, 2019 at 10:05 PM Stewart Clelland <stewartclelland at gmail.com>
wrote:

> Hi All,
>
> Based on discussion with Marten on github
> <https://github.com/numpy/numpy/issues/13797>, I have a couple of
> suggestions on syntax improvements on array transpose operations.
>
> First, introducing a shorthand for the Hermitian Transpose operator. I
> thought "A.HT" might be a viable candidate.
>

I agree that short-hand for the Hermitian transpose would make sense,
though I would try to stick with "A.H". It's one of the last reasons to
prefer the venerable np.matrix. NumPy arrays already has loads of
methods/properties, and this is a case (like @ for matrix multiplication)
where the operator significantly improves readability: consider "(x.H @
M @ x) / (x.H @ x)" vs "(x.conj().T @ M @ x) / (x.conj().T @ x)" [1].
Nearly everyone who does linear algebra with complex numbers would find
this useful.

If I recall correctly, the last time this came up, it was suggested that we
might implement this with NumPy view as  a "complex conjugate" dtype rather
than a memory copy. This would allow the operation to be essentially free.
I find this very appealing, both due to symmetry with ".T" and because of
the principle that properties should be cheap to compute.

So my tentative vote would be (1) yes, let's do the short-hand attribute,
but (2) let's wait until we have a complex conjugate dtype that do this
efficiently. My hope is that this should be relatively doable in a year or
two after current dtype refactor/usability effect comes to fruition.

Best,
Stephan

[1]  I copied the first non-trivial example off the Wikipedia page for a
Hermitian matrix:  https://en.wikipedia.org/wiki/Hermitian_matrix
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190624/ff98058f/attachment.html>


More information about the NumPy-Discussion mailing list