1

So I just started a programming course in python and I have this assignment called 'Wind data analysis' in which I am to extract data from a bin.file and sort it into x,y and z values. So far I got:

filename="turb21351_L72u.bin"
with open(filename,'br') as f: 

buffer = f.read(100000)
print("Length of buffer is %d" % len(buffer))

for i in buffer:
    print(int(i))

Which works fine (note; there are some indentation error on the script i wrote here) and gives me value in the range 1 to 300.

The problem is sorting the data. The description of the assignment sounds like this:

"The data file consists of Nz X Ny X Nx numbers (floating point single precision). The sequence of the numbers corresponds to indexes z, y and x which all increase sequentially from 1 to Nz, Ny and Nx respectively. The fastest-varying index is z, followed by y, and the slowest varying index is x. That is, the first Nz numbers from the sequence correspond to indexes z going from 1 to Nz, y = 1, and x = 1. Based on this ordering rule, the function must convert the data to a three-dimensional array with dimensions Nz X Ny X Nx."

My question is:

How is the assigniment description to be understood mathmathtically and how would one go about sorting it based on the ordering rule?

1 Answer 1

1

Can you try with the following code:

filename="turb21351_L72u.bin"
with open(filename,'br') as f:
    buffer = f.read(100000)
print("Length of buffer is %d" % len(buffer))

for i in buffer:
    print(int(i))

In python the with keyword is used when working with unmanaged resources (like file streams). The with statement works like a block statement, where it needs indentation.

From Python Docs:

The with statement clarifies code that previously would use try...finally blocks to ensure that clean-up code is executed. In this section, I’ll discuss the statement as it will commonly be used. In the next section, I’ll examine the implementation details and show how to write objects for use with this statement.

The with statement is a control-flow structure whose basic structure is:

with expression [as variable]:
    with-block

The expression is evaluated, and it should result in an object that supports the context management protocol (that is, has __enter__() and __exit__() methods).

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

1 Comment

I tried what you suggested, but it just gives me a long sequence of numbers. Im interested in receiving an array of numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.