I need to write a 2D randomized array with a size of [5][3]
into a text file. How can I write it in a single line in the text file? The output that I got from the file is in matrix form, not in a single line. The reason why I want to write it as a single line is that I want to write another array called max for the second line in the text file (I also don't know how to code this).
import numpy as np
from numpy import random
process = 5
resources = 3
allocation = [[0 for i in range(resources)]for i in range(process)]
def writeFile(allocation, process, resources):
file = open("test.txt", 'w')
for i in range(process):
for j in range(resources):
allocation = random.randint(10, size=(5, 3))
file.write(str(allocation))
file.close()
return
if __name__ == '__main__':
writeFile(allocation, process, resources)
file = open("test.txt", 'r')
allocation = np.array(file.readlines())
print(*allocation)
file.close()