-1

I'm trying to either append to an empty array or overwrite/assign new values for all elements in an array. Here is my code:

initial_income = np.arange(N) # Initial Income
red_income = np.arange(N) # Reduced Initial Income

def reduce():
    global initial_income
    global red_income
    for i in initial_income:
        red_income = (i * 0.65) / 12

The issue is that I get back 5.362500000000001 -- the last result. How do I assign these new values to the existing red_income array?

Grateful for pointers in the right direction.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Henry P.
  • 145
  • 1
  • 6

1 Answers1

1
for i, value in enumerate(initial_income):
    red_income[i] = (value * 0.65) / 12

Or simply: red_income = initial_income * 0.65 / 12

For example:

>>> np.arange(10) * .65 / 12
array([ 0.        ,  0.05416667,  0.10833333,  0.1625    ,  0.21666667,
        0.27083333,  0.325     ,  0.37916667,  0.43333333,  0.4875    ])
ForceBru
  • 43,482
  • 10
  • 63
  • 98
  • Thanks...but i'm trying to understand. What does 'i, value' achieve? – Henry P. Jul 02 '19 at 08:56
  • 1
    @HenryP., for example: `list(enumerate([1,3,2,4])) == [(0, 1), (1, 3), (2, 2), (3, 4)]`. Also see this: https://stackoverflow.com/questions/22171558/what-does-enumerate-mean. `i, value` unpacks the individual tuples. – ForceBru Jul 02 '19 at 09:00