I am trying to do a simple 1D-array shuffle in Python but keeping a copy of the original array. However, when calling shuffle commands (either np.random.shuffle or random.shuffle) Python will shuffle all of them in sync.
Example:
import numpy as np
arr = np.arange(10)
arr_backup = arr
print(arr)
print(arr_backup)
np.random.shuffle(arr)
print(arr)
print(arr_backup)
This prints:
[0 1 2 3 4 5 6 7 8 9]
[0 1 2 3 4 5 6 7 8 9]
[1 4 9 5 8 6 3 2 7 0]
[1 4 9 5 8 6 3 2 7 0]
I guess I am not understanding how Python allocates this item in the namespace or something. Any help is appreciated. Thanks.