Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
nmslib/data/genhist_nonunif.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
35 lines (28 sloc)
1.07 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |