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)
+ <class 'hooke.curve.Data'>
+ >>> 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 = {}