Skip to content

Instantly share code, notes, and snippets.

@Seanny123
Created August 23, 2016 14:38
Show Gist options
  • Save Seanny123/f925e71bb6823abf82070655b51a0d37 to your computer and use it in GitHub Desktop.
Save Seanny123/f925e71bb6823abf82070655b51a0d37 to your computer and use it in GitHub Desktop.
How to cycle through an array
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