|
From: Tim H. <tim...@co...> - 2006-01-12 14:50:50
|
Paulo J. S. Silva wrote: [SNIP] >Now the suggestion. What about adding a "transpose" property (in the >Python parlance) to ndarray objects? I would call it "t". The following >Python code explains what I mean: > >from numpy import * >class Myndarray(ndarray): > t = property(transpose, None, None) > >If you add this 3 lines to a file, import the Myndarray class, and >create one of such arrays you will get transpose(a) by simply typing >a.t. This allow for the following type of code (which I prefer): > >cost = dot(c.t, x) > >instead of > >cost = dot(transpose(c), x) > >or > >cost = dot(c.transpose(), x) > >Such a compact notation can be a blessing in code that needs lots of >transpose (like the BFGS formula for example). > >If I knew more about writing C extensions for Python I would try to do >it myself, but I don't. Is it possible to define properties in a C >extension? > > Wouldn't this be more appropriate in Matrix (I'm assuming numpy has an equivalent to Numeric/Numarray's Matrix class)? For general N-D arrays I rarely find transpose without axes arguments to be useful, so for me this would would just amount to extra cruft. -tim >Best, > >Paulo > > |