[Scipy-svn] r2967 - trunk/Lib/ndimage
scipy-svn@scip...
scipy-svn@scip...
Sat May 5 07:57:19 CDT 2007
Author: stefan
Date: 2007-05-05 07:57:06 -0500 (Sat, 05 May 2007)
New Revision: 2967
Modified:
trunk/Lib/ndimage/measurements.py
Log:
Do more precise type checking on indices.
Modified: trunk/Lib/ndimage/measurements.py
===================================================================
--- trunk/Lib/ndimage/measurements.py 2007-05-05 12:25:22 UTC (rev 2966)
+++ trunk/Lib/ndimage/measurements.py 2007-05-05 12:57:06 UTC (rev 2967)
@@ -91,20 +91,22 @@
"""Calculate the sum of the values of the array.
:Parameters:
+ labels : array of integers, same shape as input
+ Assign labels to the values of the array.
+
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
+ Examples
+ --------
- input = [0,1,2,3] and
- labels = [1,1,2,2]
+ >>> input = [0,1,2,3]
+ >>> labels = [1,1,2,2]
+ >>> sum(input, labels, index=[1,2])
+ [1.0, 5.0]
- then sum(input, labels, index=[1,2]) would yield [1,5].
-
"""
input = numpy.asarray(input)
if numpy.iscomplexobj(input):
@@ -117,9 +119,9 @@
raise RuntimeError, 'input and labels shape are not equal'
if index is not None:
T = getattr(index,'dtype',numpy.int32)
- if numpy.issubsctype(T,numpy.int64) or \
- numpy.issubsctype(T,numpy.uint64):
- raise ValueError("Index values cannot be of type int64/uint64.")
+ if T not in [numpy.int8, numpy.int16, numpy.int32,
+ numpy.uint8, numpy.uint16, numpy.bool]:
+ raise ValueError("Invalid index type")
index = numpy.asarray(index,dtype=T)
return _nd_image.statistics(input, labels, index, 0)
More information about the Scipy-svn
mailing list