Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only take median position when points exist. #14

Merged
merged 1 commit into from Oct 12, 2015
Merged

Conversation

timj
Copy link
Member

@timj timj commented Oct 12, 2015

Previously, when attempted to take the median position of a list of points we
relied on the (old, pre-1.10) NumPy behaviour of providing NaN as the median
of an empty array. Newer NumPy will raise an ImportError instead. Here, we
explicitly check that we have at least one point before taking the median.

@@ -192,7 +192,10 @@ def _kcenters(yvec, nCluster, useMedian=False, widthStdAllowed=0.15):
break

for i in range(nCluster):
centers[i] = func(yvec[clusterId == i])
if (clusterId == i).any():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like magic without a comment explaining what is going on. The clusterId == i is also used later on so maybe it would look less magic if a variable was used to avoid the repetition?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point!

@jdswinbank jdswinbank force-pushed the tickets/DM-4071 branch 2 times, most recently from 01bc3bc to ab1f342 Compare October 12, 2015 19:46
Previously, when we attempted to take the median position of a list of points we
relied on the (old, pre-1.10) NumPy behaviour of providing NaN as the median
of an empty array. Newer NumPy will raise an IndexError instead. Here, we
explicitly check that we have at least one point before taking the median.
@jdswinbank jdswinbank merged commit f23fb93 into master Oct 12, 2015
@ktlim ktlim deleted the tickets/DM-4071 branch August 25, 2018 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants