[Scipy-svn] r2963 - in trunk/Lib/ndimage: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat May 5 04:52:21 EDT 2007
Author: stefan
Date: 2007-05-05 03:52:03 -0500 (Sat, 05 May 2007)
New Revision: 2963
Modified:
trunk/Lib/ndimage/measurements.py
trunk/Lib/ndimage/tests/test_ndimage.py
Log:
Reject indices of type uint64/int64. Update documentation.
Modified: trunk/Lib/ndimage/measurements.py
===================================================================
--- trunk/Lib/ndimage/measurements.py 2007-05-05 03:14:38 UTC (rev 2962)
+++ trunk/Lib/ndimage/measurements.py 2007-05-05 08:52:03 UTC (rev 2963)
@@ -87,22 +87,39 @@
max_label = input.max()
return _nd_image.find_objects(input, max_label)
-def sum(input, labels = None, index = None):
+def sum(input, labels=None, index=None):
"""Calculate the sum of the values of the array.
- The index parameter is a single label number or a sequence of
- label numbers of the objects to be measured. If index is None, all
- values are used where labels is larger than zero.
+ :Parameters:
+ index : scalar or array
+ A single label number or a sequence of label numbers of
+ the objects to be measured. If index is None, all
+ values are used where 'labels' is larger than zero.
+
+ labels : array of same shape as input
+ Assign labels to the values of the array. For example,
+ if
+
+ input = [0,1,2,3] and
+ labels = [1,1,2,2]
+
+ then sum(input, labels, index=[1,2]) would yield [1,5].
+
"""
input = numpy.asarray(input)
if numpy.iscomplexobj(input):
raise TypeError, 'Complex type not supported'
- if labels != None:
+ if labels is not None:
labels = numpy.asarray(labels)
labels = _broadcast(labels, input.shape)
if labels.shape != input.shape:
raise RuntimeError, 'input and labels shape are not equal'
+ if index is not None:
+ index = numpy.asarray(index)
+ if numpy.issubsctype(index.dtype,numpy.int64) or \
+ numpy.issubsctype(index.dtype,numpy.uint64):
+ raise ValueError("Index values cannot be of type int64/uint64.")
return _nd_image.statistics(input, labels, index, 0)
Modified: trunk/Lib/ndimage/tests/test_ndimage.py
===================================================================
--- trunk/Lib/ndimage/tests/test_ndimage.py 2007-05-05 03:14:38 UTC (rev 2962)
+++ trunk/Lib/ndimage/tests/test_ndimage.py 2007-05-05 08:52:03 UTC (rev 2963)
@@ -2823,6 +2823,13 @@
index = [4, 8, 2])
self.failUnless(output == [4.0, 0.0, 5.0])
+ def test_sum13(self):
+ "sum 13"
+ input = numpy.array([1,2,3,4])
+ labels = numpy.array([0,0,0,0])
+ index = numpy.array([0],numpy.uint64)
+ self.failUnlessRaises(ValueError,ndimage.sum,input,labels,index)
+
def test_mean01(self):
"mean 1"
labels = numpy.array([1, 0], bool)
More information about the Scipy-svn
mailing list