From: W. Trevor King Date: Sun, 16 May 2010 18:35:01 +0000 (-0400) Subject: Fixed bugs in hooke.curve.Data.__new__ and added doctests X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4b5766e32f1df4c026cd58a3d29402dd8de9b933;p=hooke.git Fixed bugs in hooke.curve.Data.__new__ and added doctests --- diff --git a/hooke/curve.py b/hooke/curve.py index 216722d..bd58a18 100644 --- a/hooke/curve.py +++ b/hooke/curve.py @@ -44,16 +44,36 @@ class Data (numpy.ndarray): See :mod:`numpy.doc.subclassing` for the peculiarities of subclassing :class:`numpy.ndarray`. + + Examples + -------- + + >>> d = Data(shape=(3,2), info={'columns':['distance (m)', 'force (N)']}) + >>> type(d) + + >>> for i in range(3): # initialize d + ... for j in range(2): + ... d[i,j] = i*10 + j + >>> d + Data([[ 0., 1.], + [ 10., 11.], + [ 20., 21.]]) + >>> d.info + {'columns': ['distance (m)', 'force (N)']} + >>> row_a = d[:,0] + >>> row_a + Data([ 0., 10., 20.]) + >>> row_a.info + {'columns': ['distance (m)', 'force (N)']} """ - def __new__(self, subtype, shape, dtype=numpy.float, buffer=None, offset=0, + def __new__(subtype, shape, dtype=numpy.float, buffer=None, offset=0, strides=None, order=None, info=None): """Create the ndarray instance of our type, given the usual input arguments. This will call the standard ndarray constructor, but return an object of our type. """ - obj = np.ndarray.__new__(subtype=subtype, shape=shape, dtype=dtype, - buffer=buffer, offset=offset, strides=strides, - order=order) + obj = numpy.ndarray.__new__( + subtype, shape, dtype, buffer, offset, strides, order) # add the new attribute to the created instance if info == None: info = {}