I have some Python experience, but (obviously) not an overwhelming wealth of knowledge. In short, I need to create validation arrays for Neural Network testing using 1/5th of a main array. So, I am able to append i % 5 == 0 values to a test array. From there, I can still print every 5th value. Now, when I go to remove values, I get the out of index or range error; I know it is because the remove is changing the overall value of len(string_arr). However, I have been unsuccessful in figuring out a way to compensate.
Below is a 'dummy' program to solve what I need, but not the actual thing I am working on. I need 1/5th on a validation array, remove that 1/5th from the main array, and have 4/5th left on the main to train on. Below, I tried to appended to another array and remove those values in order to not mess up the len(string_arr)... did not work.
Thank you
english_list = open('file')
for word in english_list.readlines():
word = word[:-1].lower()
if len(word) == 6:
string_arr.append(word)
target_arr.append(0)
print(string_arr)
print(len(string_arr))
for i in range(len(string_arr)):
if i % 5 == 0:
test_arr.append(string_arr[i])
for i in range(len(string_arr)):
if i % 5 == 0:
one_more.append(string_arr[i])
for i in range(len(string_arr)):
if one_more[i] == string_arr:
string_arr.remove(one_more[i])
print(test_arr)
print(len(test_arr))
print(string_arr)
print(len(string_arr))