Skip to content Skip to sidebar Skip to footer

Write A 2d Array To A Text File

I have a 2d array and i want to write it to a file, the array looks almost like this: >>print (arr) [0 0 20 0 5 520 2 0 720 .... 8 -20 150 0 10 10] when i tried to write

Solution 1:

You could split your array into chunks and write each chunk separately.

Something like this should get you started:

myarr = [1,10,100,2,20,200,3,30,300,4,40]

defsplit_to_chunks(myarray, e):
    return (myarray[i:i+e] for i in xrange(0, len(myarray), e))

for i in split_to_chunks(myarr, 3):
    # etc

Post a Comment for "Write A 2d Array To A Text File"