// list of states
res = np.ndarray((len(subset)), dtype=object)
for i in range(len(subset)):
// sample the following state
s = subset[i]
// how many indexes are available?
m_available = indexes[s].shape[0]
// do we have no indexes for this state? Then insert empty array.
if (m_available == 0):
res[i] = np.zeros((0,2), dtype=int)
elif replace:
I = np.random.choice(m_available, nsample, replace=True)
res[i] = indexes[s][I,:]
else:
I = np.random.choice(m_available, min(m_available,nsample), replace=False)
res[i] = indexes[s][I,:]
return res
After Change
// list of states
res = np.ndarray(len(subset), dtype=object)
for i, s in enumerate(subset):
// how many indexes are available?
m_available = indexes[s].shape[0]
// do we have no indexes for this state? Then insert empty array.
if m_available == 0:
res[i] = np.zeros((0,2), dtype=int)
elif replace:
I = np.random.choice(m_available, nsample, replace=True)
res[i] = indexes[s][I,:]
else:
I = np.random.choice(m_available, min(m_available,nsample), replace=False)
res[i] = indexes[s][I,:]
return res