[Numpy-discussion] Re: dtype

Robert Kern robert.kern at gmail.com
Wed Feb 22 09:59:12 EST 2006


Colin J. Williams wrote:
> I've been trying to gain some understanding of dtype from the builtin
> documentation and would appreciate advice.
> 
> I don't find anything in http://projects.scipy.org/scipy/numpy or
> http://wiki.python.org/moin/NumPy
> 
> Chapter 2.1 of the book has a good overview, but little reference material.
> 
> In the following, dt= numpy.dtype
> 
> Some specific problems are flagged ** below.
> 
> Colin W.
> 
> [Dbg]>>> h(dt)
> Help on class dtype in module numpy:
> 
> class dtype(__builtin__.object)
> |  Methods defined here:
> | |  __cmp__(...)
> |      x.__cmp__(y) <==> cmp(x,y)
> | |  __getitem__(...)
> |      x.__getitem__(y) <==> x[y]
> | |  __len__(...)
> |      x.__len__() <==> len(x)
> | |  __reduce__(...)
> |      self.__reduce__()  for pickling.
> | |  __repr__(...)
> |      x.__repr__() <==> repr(x)
> | |  __setstate__(...)
> |      self.__setstate__()  for pickling.
> | |  __str__(...)
> |      x.__str__() <==> str(x)
> | |  newbyteorder(...)
> |      self.newbyteorder(<endian>) returns a copy of the dtype object
> |      with altered byteorders.  If <endian> is not given all byteorders
> |      are swapped.  Otherwise endian can be '>', '<', or '=' to force
> |      a byteorder.  Descriptors in all fields are also updated in the
> |      new dtype object.
> | |  ----------------------------------------------------------------------
> |  Data and other attributes defined here:
> | |  __new__ = <built-in method __new__ of type object>   |     
> T.__new__(S, ...) -> a new object with type S, a subtype of
> T               ** What are the parameters?  In other words,
> |                                                                                                                        
> what does ... stand for?  **

http://www.python.org/2.2.3/descrintro.html#__new__

"""Recall that you create class instances by calling the class. When the class
is a new-style class, the following happens when it is called. First, the
class's __new__ method is called, passing the class itself as first argument,
followed by any (positional as well as keyword) arguments received by the
original call. This returns a new instance. Then that instance's __init__ method
is called to further initialize it. (This is all controlled by the __call__
method of the metaclass, by the way.)
"""

> **  There is no __module__ attribute.  How does one identify the modules
> holding the code?  **

It's an extension type PyArray_Descr* in numpy/core/src/arrayobject.c .

-- 
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