[Numpy-discussion] add .H attribute?

Bryan Van de Ven bryanv at continuum.io
Mon Jul 22 16:04:47 EDT 2013

On the other hand, the most salient quality an unavoidable copy is that it is unavoidable. For people for whom using Hermitian conjugates is common, it's not like they won't do it just because they can't avoid a copy that can't be avoided.  Given that if a problem dictates a Hermitian conjugate be taken, then it will be taken, then: a.H is closer to the mathematical notation, eases migration for matlab users, and does not require everyone to reinvent their own little version of the same function over and over. All of that seems more compelling that this particular arbitrary convention, personally. 


On Jul 22, 2013, at 3:10 PM, Nathaniel Smith <njs at pobox.com> wrote:

> On Thu, Jul 18, 2013 at 3:18 PM, Stéfan van der Walt <stefan at sun.ac.za> wrote:
>> On Sat, Jul 13, 2013 at 7:46 PM, Nathaniel Smith <njs at pobox.com> wrote:
>>> Why not just write
>>> def H(a):
>>>    return a.conj().T
>> It's hard to convince students that this is the Best Way of doing
>> things in NumPy.  Why, they ask, can you do it using a' in MATLAB,
>> then?
> I guess I'd try to treat it as a teachable moment... the answer points
> to a basic difference in numpy versus MATLAB. Numpy operates at a
> slightly lower level of abstraction. In MATLAB you're encouraged to
> think of arrays as just mathematical matrices and let MATLAB worry
> about how to actually represent those inside the computer. Sometimes
> it does a good job, sometimes not. In numpy you need to think of
> arrays as structured representations of a chunk of memory. There
> disadvantages to this -- e.g. keeping track of which arrays return
> view and which return copies can be tricky -- but it also gives a lot
> of power: views are awesome, you get better interoperability with C
> libraries/Cython, better ability to predict which operations are
> expensive or cheap, more opportunities to use clever tricks when you
> need to, etc.
> And one example of this is that transpose and conjugate transpose
> really are very different at this level, because one is a cheap stride
> manipulation that returns a view, and the other is a (relatively)
> expensive data copying operation. The convention in Python is that
> attribute access is supposed to be cheap, while function calls serve
> as a warning that something expensive might be going on. So in short:
> MATLAB is optimized for doing linear algebra and not thinking too hard
> about programming; numpy is optimized for writing good programs.
> Having .T but not .H is an example of this split.
> Also it's a good opportunity to demonstrate the value of making little
> helper functions, which is a powerful technique that students
> generally need to be taught ;-).
> -n
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list