-1

I have two variables of data (BxHPF and ByHPF), which are equall in number of data. I would like to make a loop, which takes first value of BxHPF and ByHPF compute them, then take next one from BxHPF and ByHPF and so on. For now I have:

So I though about this way:

Computing = (float(BxHPF[0])/float(ByHPF[0]))
Dat1 = math.degrees(Computing)*(-1)

In fact those equations give me correct result. But as I wrote I need to make a loop, which will count every pair from BxHPF and ByHPF with using those two variables Computing and Dat1.

To be exact BxHPF and ByHPF contain 266150 records each.

Hiddenguy
  • 547
  • 13
  • 33

2 Answers2

2

Not sure exactly what you mean with "count", but if you just want to put that computation into a loop, do this:

result = []

for x,y in zip(BxHPF,ByHPF):
    result.append(math.degrees(float(x)/y)*(-1))

btw: you don't need to use float twice. Python does a "float division" if the dividend or the divisor is float

Any idea on how to save it?

with open('output.txt') as f:
    f.write("\n".join([str(i) for i in result]))
hansaplast
  • 11,007
  • 2
  • 61
  • 75
  • 1
    Or alternatively, use list comprehension. `result = [math.degrees(x/y)*(-1) for x,y in zip(BxHPF,ByHPF)]`. – user202729 Jan 07 '18 at 13:38
  • yeah, I didn't want to shoot with list comprehension as the op seems to be new to python – hansaplast Jan 07 '18 at 13:39
  • Why so much hate, I am a beginner. Is it difficult for you to politely answer a question? There is no need to downvote, my question. – Hiddenguy Jan 07 '18 at 15:08
  • 1
    @Hiddenguy I didn't downvote you. Yeah, stackoverflow is rough for beginners. Don't worry, it's getting better over time – hansaplast Jan 07 '18 at 16:02
0

All credits to @user202729 who solved my problem. Thank you.

result = [math.degrees(x/y)*(-1) for x,y in zip(BxHPF,ByHPF)]
Hiddenguy
  • 547
  • 13
  • 33