import numpy as np
arr = np.random.rand(9).reshape((3, 3))
labels = (arr > 0.5).astype(np.uint)
print(arr)
print(labels)
for label in np.unique(labels):
mask = labels == label
print(label, np.mean(arr[mask]))
--
You received this message because you are subscribed to the Google Groups "scikit-image" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com.
To post to this group, send email to scikit...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/scikit-image/87b5d106-00d9-44bf-a89b-bff09ca7d00b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi,I probably didn't explain it very well, but that was the sort of loop I meant when I said "loop over all of the values of the image calculating it for each one" (values was probably a bad choice of word, I meant individual label values).I was wondering whether there was a more efficient way to do this using some sort of clever numpy or skimage function? That is, without manually looping over each label value (ie. 0 to the number of labels).
To view this discussion on the web, visit https://groups.google.com/d/msgid/scikit-image/eb3eaa76-ddbd-4a79-964e-2f479e924e57%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/scikit-image/CAM07sM6eXVGkdh1TFLPOYYBYGjcb1Oh5WsBV%2B_445fN_JxttQg%40mail.gmail.com.