I have the following function that resamples 100 times a file of ~800 elements:
def resample(arg_array):
all_sets = []
i = 1
while i <= 100:
subset = np.random.choice(arg_array, 100, replace=True)
all_sets.append(subset)
i += 1
return all_sets
This produces a list of arrays with 100 elements each, stored in all_sets.
I need to split this list and save each array into a new variable. Thought about doing list comprehension, but doing set1, set2, ..., set100 = [list comprehension] just doesn't seem very efficient or elegant at all.
Would be great if Python had something like bash where you can generate a new variable name for each pass in a loop.
setattr()But I'd be surprised if you really need to do that rather than just accessing the list elements by their index. Can you expand a bit more on the use case?