0

I have a 3D-array storing temperature data. And me want to put it to text file in one single line. Need to re-write this code in pythonic way.

    for jn in range(X1, X2):
        for jm in range(Y1,Y2):
            fl.write(str((t[jn,jm] - 273.1).astype(int))+" ")
    fl.write("\n")
2
  • 1
    What does your output look like when you do this? Commented Aug 9, 2013 at 6:28
  • File has one line like as 23 24 25 ... Commented Aug 11, 2013 at 1:00

2 Answers 2

4

Assuming your array to save is t:

t.tofile('yourfile.txt',sep=" ",format="%s")

Also see this question:

How to write a multidimensional array to a text file?

Sign up to request clarification or add additional context in comments.

Comments

2
values = ("{0:.0f}".format(t[i,j]-273.1) 
                for i in xrange(X1, X2) 
                for j in xrange(Y1,Y2))
line = " ".join(values)
fl.write(line + "\n")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.