Created
August 23, 2016 14:38
-
-
Save Seanny123/f925e71bb6823abf82070655b51a0d37 to your computer and use it in GitHub Desktop.
How to cycle through an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
arr = ["A", "B", "C", "D"] | |
# I want this to cycle every 0.5s | |
# so I should see this list printed twice | |
# with each item printed 5 times | |
idx = 0 | |
arr_len = len(arr) | |
t_len = 0.5 | |
for t in np.arange(0, 4.0, 0.1): | |
idx = int(np.floor(t % (t_len * arr_len) / t_len)) # this line is the solution | |
print(arr[idx]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment