I always use logical masks for such things, you might think:
# Mask every sixth row mask = (np.arange(images.shape[0]) % 6) != 0
Then each masked element will be a check set:
validation_images = images[~mask]
Mathematical operations on the element of work of the numpy array are wise, therefore, for each element modulo ( % ) another array with the same shape will be executed. != 0 also works on elements and compares if the module is not equal to zero. Thus, the mask is an array containing False , where the value is not int * 6 and True , where it is.
source share