What is .T?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

What is .T?

Keith Goodman
What is .T? It looks like an attribute, behaves like a method, and
smells like magic. I'd like to add it to my class but don't no where
to begin.
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: What is .T?

Robert Kern-2
On Tue, May 6, 2008 at 2:22 PM, Keith Goodman <[hidden email]> wrote:
> What is .T? It looks like an attribute, behaves like a method, and
>  smells like magic. I'd like to add it to my class but don't no where
>  to begin.

It is a property. It returns the transpose of the array. If you had a
.transpose() method on your class already, you could do (in Python
2.4+)

  @property
  def T(self):
      return self.transpose()

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: What is .T?

Keith Goodman
On Tue, May 6, 2008 at 12:28 PM, Robert Kern <[hidden email]> wrote:

>
> On Tue, May 6, 2008 at 2:22 PM, Keith Goodman <[hidden email]> wrote:
>  > What is .T? It looks like an attribute, behaves like a method, and
>  >  smells like magic. I'd like to add it to my class but don't no where
>  >  to begin.
>
>  It is a property. It returns the transpose of the array. If you had a
>  .transpose() method on your class already, you could do (in Python
>  2.4+)
>
>   @property
>   def T(self):
>       return self.transpose()

That works very nicely. Thank you.
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion