0

When I cycle through, the issue is that it takes the first value only and does not apply the second and third values. I want this to cycle 20 times to get a better understanding of what's going on. I have looked at W3 schools and other resources and I don't know where I am running into an issue

#Creating a loop to run through 

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

a1_0 = Three_Time     #Array 1 initial value
a2_0 = Two_Time     #Array 2 initial value
i = 0
time = [0]
Hour_cap = 20
array1 = np.array([a1_0]* i)
array2 = np.array([a2_0] * i )

while i < Hour_cap:
    i += 1
    time = np.append(time, i)
    array1 = np.append(array1, array1[i]) 
    array2 = np.append(array2, array2[i])

Expected Output: array1[0,192,384....]
8
  • 1
    It would help us understand what was going on if your code were correctly indented. It's hard to know what's inside the while loop. Commented Dec 30, 2020 at 17:32
  • Please include your import statements as well, so its easier to decode. Commented Dec 30, 2020 at 17:33
  • Could you please share output of the script as well as your expected output, to better understand the issue. Commented Dec 30, 2020 at 17:36
  • @Spencer You should use empty lists, append to them and only then convert them to numpy arrays. np.append is going to take much more time. Commented Dec 30, 2020 at 17:41
  • @Spencer I see you've updated your code. Does it work now? Commented Dec 30, 2020 at 17:48

1 Answer 1

2

your loop never started

change i > Hour_cap to i < Hour_cap

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.