0

is there are way to write this more comfortable in python?

quote_e[i] = [i, (1 * o +
 2 * p +
 3 * q +
 4 * r +
 5 * s +
 6 * t +
 7 * u +
 8 * v +
 9 * w +
 10 * x +
 11 * y +
 12 * z) / 78]

The variables are from a list that was created before.

o = ema_12[i - 12][1]
 p = ema_12[i - 11][1]
 q = ema_12[i - 10][1]
 r = ema_12[i - 9][1]
 s = ema_12[i - 8][1]
 t = ema_12[i - 7][1]
 u = ema_12[i - 6][1]
 v = ema_12[i - 5][1]
 w = ema_12[i - 4][1]
 x = ema_12[i - 3][1]
 y = ema_12[i - 2][1]
 z = ema_12[i - 1][1]

Thanks in advance.

Daniel

asked May 6, 2020 at 6:42
6
  • 1
    Could you please explain more specifically what you mean by "more comfortable"? Commented May 6, 2020 at 6:44
  • 1
    What are all these variables? Where do they come from? We don't know, we can't help. Just a guess: maybe you should use a list rather than all of there unrelated variables? Commented May 6, 2020 at 6:46
  • Hi kingkupps. Sure. I meant that I think, that there could be a way to write it shorter. More efficient. Something like letters (uprising) * numbers (uprising). I hope that describes it better. Commented May 6, 2020 at 6:49
  • Hi, Thierry. The variables are from a list. o = ema_12[i - 12][1] p = ema_12[i - 11][1] q = ema_12[i - 10][1] r = ema_12[i - 9][1] s = ema_12[i - 8][1] t = ema_12[i - 7][1] u = ema_12[i - 6][1] v = ema_12[i - 5][1] w = ema_12[i - 4][1] x = ema_12[i - 3][1] y = ema_12[i - 2][1] z = ema_12[i - 1][1] Commented May 6, 2020 at 6:51
  • Please edit your question to include all relevant information - as you can see, code in comments is pretty unreadable... Commented May 6, 2020 at 6:51

1 Answer 1

1
var_list =[ ema_12[i-j][1] for j in range(12,0,-1) ]
quote_e[i]=[i,(np.arange(1,13)*var_list)/78]

This creates your list of variable o to z.Here muliplication will be element-wise

I hope this is what you required

answered May 6, 2020 at 7:08
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. That was what I was looking for.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.