Conjugate transpose operator “.H” in numpy

You can subclass the ndarray object like:

from numpy import ndarray

class myarray(ndarray):    
    @property
    def H(self):
        return self.conj().T

such that:

a = np.random.rand(3, 3).view(myarray)
a.H

will give you the desired behavior.

Edit:

As suggested by @slek120, you can force to transpose only the last 2 axes with:

self.swapaxes(-2, -1).conj()

instead of self.conj().T.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)