IndexError: arrays used as indices must be of integer (or boolean) type

def _resample_data(X, y, N):

    """Limit sampling to N instances per class."""

    if N > 0:

        # Split labels into set of indexes for each class

        class_idxs = [np.where(y == c)[0] for c in np.unique(y)]

        # Shuffle each of sets of indexes

        [np.random.shuffle(i) for i in class_idxs]

        # Take N indexes, or fewer if total is less than N

        subset_idx = [i[:N] if len(i) >= N else i for i in class_idxs]

        # Use advanced indexing to get subsets of X and y


        idxs = np.array(subset_idx).ravel()


        X, y = X[idxs], y[idxs]

    return X, y

X,y = {},{}

tgt_num = 100

X[‘tgt’], y[‘tgt’] = _resample_data(tgt_X, tgt_y, tgt_num)
/usr/local/lib/python3.7/dist-packages/ VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify ‘dtype=object’ when creating the ndarray
from ipykernel import kernelapp as app

IndexError Traceback (most recent call last)
in ()
1 X,y = {},{}
2 tgt_num = 100
----> 3 X[‘tgt’], y[‘tgt’] = _resample_data(tgt_X, tgt_y, tgt_num)

in _resample_data(X, y, N)
15 idxs = np.array(subset_idx).ravel()
16 np.random.shuffle(idxs)
—> 17 X, y = X[idxs], y[idxs]
19 return X, y

IndexError: arrays used as indices must be of integer (or boolean) type

Please help anyone urgently!!!

  1. Check whether class_idxs is empty or not
  2. If class_idxs is not empty, type casting is probably what you want
idx = idx.astype(np.int64)

I think your question is kinda closer to Stackoverflow instead of here.
Anyway, I hope you can solve