Trying to access subset of mnist dataset in pytorch [equal samples from each class]
Trying to access subset of mnist dataset in pytorch [equal samples from each class] but getting this error
prng = RandomState(42)
random_permute = prng.permutation(np.arange(0, 6000))[0:3000]
indx = np.concatenate([np.where(np.array(mnist_data.targets) == classe)[0][random_permute] for classe in range(0,10)])

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
&lt;ipython-input-178-038015f76b77&gt; in &lt;module&gt;
----&gt; 1 indx = np.concatenate([np.where(np.array(mnist_data.targets) == classe)[0][random_permute] for classe in range(0,10)])

&lt;ipython-input-178-038015f76b77&gt; in &lt;listcomp&gt;(.0)
----&gt; 1 indx = np.concatenate([np.where(np.array(mnist_data.targets) == classe)[0][random_permute] for classe in range(0,10)])

IndexError: index 5992 is out of bounds for axis 0 with size 5923


MNIST dataset does not have a uniform distribution of targets. You are getting this error because class 0 in MNIST contains 5923 samples.
nums = [0]*10
for i in range(60000):
  nums[(int(mnist_data.targets[i]))] += 1
print(nums)

This will print [5923, 6742, 5958, 6131, 5842, 5421, 5918, 6265, 5851, 5949].
