From 4b5766e32f1df4c026cd58a3d29402dd8de9b933 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 16 May 2010 14:35:01 -0400 Subject: [PATCH] Fixed bugs in hooke.curve.Data.__new__ and added doctests --- hooke/curve.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) 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 = {} -- 2.26.2