I have a file with the content of
18
21
24
27
30
And the array of
[[ 1 6 11]
[ 2 7 12]
[ 3 8 13]
[ 4 9 14]
[ 5 10 15]]
How can I write this array to file so that each row will be corresponding with the appropriate lines such as it becomes something like this:
18 1 6 11
21 2 7 12
24 3 8 13
27 4 9 14
30 5 10 15
I have used this code, but it does not write the code as I want. The code:
import numpy as np
ourlist = []
for i in range(1, 16):
ourlist.append(i)
mydata = np.matrix([ourlist])
array_from_list=(mydata.reshape(3, 5))
x_transpose = (np.transpose(array_from_list)) # the array above
with open('5rows.txt','a') as f: #the file containing numbers
for elements in x_transpose:
f.write(str(elements))
f.write('\n')
It instead writes elements to the end of line. If possible, could you tell me how I can do this, please ? I really appreciate your help !