mattnedrich / MeanShift_py

Simple implementation of mean shift clustering in python
MIT License
293 stars 100 forks source link

Redundant index variable #8

Closed sunxiayi closed 6 years ago

sunxiayi commented 6 years ago

Hi mat, I appreciate your code! However in the following code, when I inspect the variable index, I found that the it is initialized once and then incremented in the loop, however it is never used to assign to anything. And this variable isn't passed to any other function, too. So I wonder is this a redundant variable? If so I think deleting it would make the logic clearer.

def group_points(self, points):
        group_assignment = []
        groups = []
        group_index = 0
        index = 0 # initialization
        for point in points:
            nearest_group_index = self._determine_nearest_group(point, groups)
            if nearest_group_index == None:
                # create new group
                groups.append([point])
                group_assignment.append(group_index)
                group_index += 1
            else:
                group_assignment.append(nearest_group_index)
                groups[nearest_group_index].append(point)
            index += 1 #increment
        return np.array(group_assignment)
mattnedrich commented 6 years ago

Thanks, I pushed an update