From 658214d5d13d98a8654937b90407039bb01f5a16 Mon Sep 17 00:00:00 2001 From: Leonid Boytsov Date: Fri, 12 Apr 2019 21:08:36 -0400 Subject: [PATCH] xrange -> range (for Python3) --- data/genhist_nonunif.py | 35 ----------------------------------- data/genhist_unif.py | 4 ++-- 2 files changed, 2 insertions(+), 37 deletions(-) delete mode 100755 data/genhist_nonunif.py diff --git a/data/genhist_nonunif.py b/data/genhist_nonunif.py deleted file mode 100755 index 3e25ded..0000000 --- a/data/genhist_nonunif.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -# -# This script is released under the -# Apache License Version 2.0 http://www.apache.org/licenses/. -# -# It generates vectors with coordinates sampled randomly and uniformly from [0,1] -# If one specifies the flag -b or --binary, the script generates only binary data -# - -import random -import argparse -import sys -import numpy - -parser = argparse.ArgumentParser(description='vector generator (uniform)') - -parser.add_argument('-d','--dim', required=True, type=int, help='dimensionality (# of vector elements)') -parser.add_argument('-n','--ndata', required=True, type=int, help='# of data points') -parser.add_argument('-o','--outf', required=True, help='output file') -parser.add_argument('--min_val', default=1e-5, help='the minimum possible vector element') - -args = vars(parser.parse_args()) - -nd = args['ndata'] -outf = args['outf'] -dim = args['dim'] -minVal=args['min_val'] - -f=open(outf, 'w') -for i in xrange(nd): - arr = numpy.array([random.random() for _ in xrange(dim)]) - arr /= sum(arr) - f.write("\t".join([("%g" % max(v,minVal)) for v in arr]) + "\n") -f.close() - diff --git a/data/genhist_unif.py b/data/genhist_unif.py index c3dc40a..71a3060 100755 --- a/data/genhist_unif.py +++ b/data/genhist_unif.py @@ -28,10 +28,10 @@ dim = args['dim'] minVal=args['min_val'] f=open(outf, 'w') -for i in xrange(nd): +for i in range(nd): # See an explanation from this blog post http://blog.geomblog.org/2005/10/sampling-from-simplex.html # There's more on sampling from the simplex: Luc Devroye's book, 'Non-Uniform Random Variate Generation'. - arr = numpy.array([-math.log(random.random()) for _ in xrange(dim)]) + arr = numpy.array([-math.log(random.random()) for _ in range(dim)]) arr /= sum(arr) f.write("\t".join([("%g" % max(v,minVal)) for v in arr]) + "\n") f.close()