Skip to content

Instantly share code, notes, and snippets.

@lfyzjck
Last active January 25, 2016 14:44
Show Gist options
  • Save lfyzjck/6b7b5984b2df6d25ff21 to your computer and use it in GitHub Desktop.
Save lfyzjck/6b7b5984b2df6d25ff21 to your computer and use it in GitHub Desktop.
simple script to generate random matrix and export to csv
import random
import csv
def export_matrix(box, output_file='matrix.csv'):
with open(output_file, 'w') as f:
writer = csv.writer(f, delimiter=',')
for line in box:
writer.writerow(line)
def random_matrix(rows, cols, max_number=10000):
return [[random.randint(0, max_number) for j in range(rows)] for i in range(cols)]
if __name__ == '__main__':
box = random_matrix(20, 100)
export_matrix(box)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment