[Numpy-discussion] Two bugs in numpy 0.9.2 and a suggestion.
Tim Hochberg
tim.hochberg at cox.net
Thu Jan 12 06:51:09 EST 2006
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
>
>
More information about the NumPy-Discussion
mailing list