def test_hclust(self): x_vals = numpy.random.rand(10) y_vals = numpy.random.rand(10) xys = zip(x_vals, y_vals) distance = 0.2 clusters = cluster_r.hclust(xys, distance, "single")
parser.add_argument('--clusters', '-c', action='store_true', default=False, help='output points') args = parser.parse_args() # convert csv to array of float tuples rows = csv.reader(args.input) pts = map(lambda row: (float(row[0]), float(row[1])), rows) if(len(pts) < 1): sys.stderr.write("No input points found") exit() # convert meters to kilometers since hclust assumes km km = args.distance / 1000.0 clusters = cluster_r.hclust(pts, km, args.method) clusters.sort(key=len, reverse=True) centroids = [] for cluster in clusters: unzipped = zip(*cluster) centroids.append(util.points_to_centroid(unzipped)) if args.clusters: print('clusters') for cluster in clusters: print cluster if args.centroids: print('centroids') for centroid in centroids: print centroid