Conjugate transpose operator “.H” in numpy

后端 未结 2 989
死守一世寂寞
死守一世寂寞 2020-12-14 09:04

It is very convenient in numpy to use the .T attribute to get a transposed version of an ndarray. However, there is no similar way to get the conj

2条回答
  •  天涯浪人
    2020-12-14 09:35

    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.random((3, 3)).view(myarray)
    a.H
    

    will give you the desired behavior.

提交回复
热议问题