# LinearExpLog10.py, D. Parson, September 13, 2023 # 1. Read CSC223f23CSVassn1.csv # 2. Sort on NPExponent20, which also sorts NPExp20Log2 which is # log2(NPExponent20+1) for each row of data. # 3. Create derived attribute BinNPExp20A, starting at 0 and incrementing # by 1 every time a new, larger value for NPExponent20 is encountered in # a row. # 4. Write a CSV output file LinearExpLog10.csv # with BinNPExp20A, NPExponent20, NPExp20Log2. import csv from math import log10 from random import Random rgen = Random(1234542) if __name__ == '__main__': outfile = open('LinearExpLog10.csv', 'w') outcsv = csv.writer(outfile, delimiter=',', quotechar='"') outcsv.writerow(['LinearA', 'LinearB','Exponential', 'Log10']) for rowix in range(0, 10000): LinearA = rgen.randint(0,100) LinearB = rgen.randint(25,75) Exponential = 2 ** (LinearA + LinearB + rgen.randint(0,20)) # rgen.randint(0,20) is for some random noise in the data # expand using base 2, compress with base 10 Log10 = log10(Exponential+1) # +1 in case of 0 in real data outcsv.writerow([LinearA, LinearB, Exponential, Log10]) outfile.close()