FIX: Address non-int DeprecationWarning from NumPy

This commit is contained in:
Josh Warner (Mac)
2014-05-07 23:54:17 -05:00
parent d142748a86
commit 069cba50ef
+4 -2
View File
@@ -71,7 +71,7 @@ def relabel_sequential(label_field, offset=1):
-------
relabeled : numpy array of int, same shape as `label_field`
The input label field with labels mapped to
{1, ..., number_of_labels}.
{offset, ..., number_of_labels}.
forward_map : numpy array of int, shape ``(label_field.max() + 1,)``
The map from the original label space to the returned label
space. Can be used to re-apply the same mapping. See examples
@@ -113,16 +113,18 @@ def relabel_sequential(label_field, offset=1):
>>> relab, fw, inv = relabel_sequential(label_field, offset=5)
>>> relab
array([5, 5, 6, 6, 7, 9, 8])
"""
m = label_field.max()
if not np.issubdtype(label_field.dtype, np.int):
new_type = np.min_scalar_type(int(m))
label_field = label_field.astype(new_type)
m = label_field.max() # Ensures m is an integer
labels = np.unique(label_field)
labels0 = labels[labels != 0]
if m == len(labels0): # nothing to do, already 1...n labels
return label_field, labels, labels
forward_map = np.zeros(m+1, int)
forward_map = np.zeros(m + 1, int)
forward_map[labels0] = np.arange(offset, offset + len(labels0) + 1)
if not (labels == 0).any():
labels = np.concatenate(([0], labels))