[Numpy-discussion] Syntax Improvement for Array Transpose

Todd toddrjen at gmail.com
Mon Jun 24 11:10:35 EDT 2019


On Mon, Jun 24, 2019 at 11:00 AM Stephan Hoyer <shoyer at gmail.com> wrote:

> 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
>
>
I would call it .CT or something like that, based on the term "Conjugate
transpose".  Wikipedia redirects "Hermitian transpose" to "Conjugate
transpose", and google has 49,800 results for "Hermitian transpose" vs
201,000 for "Conjugate transpose" (both with quotes).  So "Conjugate
transpose" seems to be the more widely-known name.  Further, I think what a
"Conjugate transpose" does is immediately obvious to someone who isn't
already familiar with the term so long as they know what a "conjugate" and
"transpose" are, while no one would be able to tell what a "Hermitian
transpose" unless they are already familiar with the name.  So I have no
problem calling it a "Hermitian transpose" somewhere in the docs, but I
think the naming and documentation should focus on the "Conjugate
transpose" term.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190624/292a4ff5/attachment.html>


More information about the NumPy-Discussion mailing list