[Numpy-discussion] Re: Constructor parameters - was Re: dtype

Robert Kern robert.kern at gmail.com
Wed Feb 22 14:11:05 CST 2006

Colin J. Williams wrote:

> Robert,
> Many thank for this.  You have described the standard Python approach to
> constructing an instance.  As I understand it,
> numpy uses the __new__ method, but not __init__,  in most cases.
> My interest is in " any (positional as well as keyword) arguments".
> What should the user feed the constuctor?  This isn't clear from the
> online documentation.

Look in the code. The PyArrayDescr_Type method table gives arraydescr_new() as
the implementation of the tp_new slot (the C name for __new__). You can read the
implementation for information. Patches for documentation will be gratefully

That said:

In [16]: a = arange(10)

In [17]: a.dtype
Out[17]: dtype('>i4')

In [18]: dtype('>i4')
Out[18]: dtype('>i4')

If you want complete documentation on data-type descriptors, it's in Chapter 7
of Travis's book.

> From a Python user's point of view, the module holding the dtype class
> appears to be multiarray.
> The standard Python approach is to put the information in a __module__
> attribute so that one doesn't have to go hunting around.  Please see below.

<shrug> dtype.__module__ (== 'numpy') tells you the canonical place to access it
from Python code. It will never be able to tell you what C source file to look
in. You'll have to break out grep no matter what.

> While on the subject of the Standand Python aproach, class names usually
> start with an upper case letter and the builtins have their own style,
> ListType etc.  numpy equates ArrayType to ndarray but ArrayType is
> deprecated.

ListType, TupleType et al. are also deprecated in favor of list and tuple, etc.

But yes, we do use all lower-case names for classes. This is a conscious
decision. It's just a style convention, just like PEP-8 is just a style
convention for the standard library.

Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

More information about the Numpy-discussion mailing list