On Fri, Jun 17, 2011 at 13:27, Christopher Barker <[email protected]> wrote:
> Actually, I'm a bit confused about dtypes from an OO design perspective > anyway. I note that the dtypes seem to have all (most?) of the methods > of ndarrays (or placeholders, anyway), which I don't quite get. No, they don't. [~] |33> d = np.dtype(float) [~] |34> dir(d) ['__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', 'alignment', 'base', 'byteorder', 'char', 'descr', 'fields', 'flags', 'hasobject', 'isbuiltin', 'isnative', 'itemsize', 'kind', 'metadata', 'name', 'names', 'newbyteorder', 'num', 'shape', 'str', 'subdtype', 'type'] The numpy *scalar* types do, because they are actual Python types just like any other. They provide the *unbound* methods (i.e. you cannot call them) that will be bound when an instance of it gets created. And the scalar types have many of the same methods as ndarray to allow some ability to write generic functions that will work with either arrays or scalars. -- 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 [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
