[Numpy-discussion] ndarray newbie question

Pierre GM pgmdevlist at gmail.com
Fri Jan 5 04:56:56 EST 2007

belinda thom wrote:
>  > Some context: the type of introspection I'm often wishing I could do
>  > in a single, easy command usually has to do w/getting to know the
>  > software better.

For generic introspection in Python, dir and .__doc__ are very useful.
The ? trick works in ipython and prints the __doc__.

> When I try the latter recommendation above w/numpy arrays, I get:
> Type:           NoneType
> Base Class:     <type 'NoneType'>
> String Form:    None
> Namespace:      Interactive
> Docstring:
>      <no docstring>

I agree that this one is not really informative. A
>>> a.__class__.__doc__?
provides a  docstring interestingly truncated under ipython, but nothing 
useful either.

However, you may want to consider the combination:
>>> for k in dir(a):
>>>     try:
>>>          print "\n",k, getattr(a,k).__doc__
>>>     except AttributeError:
>>>          pass

But I'm a bit confused: what are you really trying to achieve by querying the 
methods of a numpy array ? The wiki page
is quite educational, and provides many examples of usage you won't find in 
the docstrings.

More information about the NumPy-Discussion mailing list