How can I implement for loop in Python?

Create both B and C as Numpy arrays:

C = np.array([ 0, 0, 2, 1, 1, 8, 3, 6, 6, 7, 11, 8, 10, 23, 22, 12, 15, 34, 16,
    9, 11, 6, 0, 0])
B = np.array([500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500,
    6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 10500, 11000, 11500,
    12000])

Then compute EU just as multiplication of both source arrays, without any loop:

EU = C * B

And the rest of your code (to compute ENU_1 and ENU_2) is OK.

But you wrote that you wanted the output in one array and this is unclear.
Do you want to concatenate 3 arrays computed so far?

If this is the case, run e.g.:

result = np.concatenate((EU, ENU_1, ENU_2))

Note double parentheses, because:

  • the external parentheses are a “container” for parameters,
  • the interal parentheses (with what is inside) create a tuple – the
    first (and only) parameter of this function – the sequence of arrays
    to concatenate.

Browse More Popular Posts

Leave a Comment