Skip to content
Advertisement

How can i make this calculations from file?

I have a file contains two columns and need to apply this equation on them like

JavaScript

the equation is

JavaScript

it means the result will be a column

JavaScript

and do this equation for each point x1 to other points and y1 for other points until finished then start to calculate

JavaScript

and do this equation for each point x2 to other points and y2 for other points until finished and so on until finished all x and y and store the result in a file

I tried to do this by using 2 arrays and stored the numbers on them then make calculations but the data is too huge and the array will be the wrong choice .. how can I do this in python .. reading from file the I and j for each value

my tries and sorry if it’s too bad

JavaScript

i got

JavaScript

I did the calculations in excel but trying to use python for it too Should I put each column in a separate file to be easier for catching numbers or can I do this with the same file?

*

Advertisement

Answer

You need to loop through the input file twice. The second loop can skip all the lines that are before the line from the first loop.

If you could load the file contents into a list or array, you could do this more easily by iterating over indexes rather than skipping lines.

Also, you should only open the output file once. You’re overwriting it every time through the loop.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement