Repeatedly loading arrays in __getitem__
before indexing it is expensive and you won’t have any benefit from it, as you are already loading the entire array.
Move it to the __init__
and just index the array in the __getitem__
.
Alternatively, revisit your approach and check if you can split the data into separate files, index the file list, and load the actual sample only in the __getitem__
.