[Numpy-discussion] numpy.array and subok kwarg

Darren Dale dsdale24@gmail....
Thu Jan 22 08:15:37 CST 2009


I have a test script:

import numpy as np

class MyArray(np.ndarray):

    __array_priority__ = 20

    def __new__(cls):
        return np.asarray(1).view(cls).copy()

    def __repr__(self):
        return 'my_array'

    __str__ = __repr__

    def __mul__(self, other):
        return super(MyArray, self).__mul__(other)

    def __rmul__(self, other):
        return super(MyArray, self).__rmul__(other)

mine = MyArray()
print type(np.array(mine,dtype='f'))

The type returned by np.array is ndarray, unless I specifically set
subok=True, in which case I get a MyArray. The default value of subok is
True, so I dont understand why I have to specify subok unless I want it to
be False. Is my subclass missing something important?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090122/3e2ac281/attachment.html 

More information about the Numpy-discussion mailing list