Only integer scalar arrays can be converted to a scalar index


I want to create a function that randomly selects items from a training set using the given bin probabilities. I divide the defined indices into 11 boxes and assign a specific probability to each of them.

bin_probs = [0.5, 0.3, 0.15, 0.04, 0.0025, 0.0025, 0.001, 0.001, 0.001, 0.001, 0.001]X_train = list(range(2000000))train_probs = bin_probs * int(len(X_train) / len(bin_probs)) # extend probabilities across bin elementstrain_probs.extend([0.001]*(len(X_train) - len(train_probs))) # a small fix to match number of elementstrain_probs = train_probs/np.sum(train_probs) # normalizeindices = np.random.choice(range(len(X_train)), replace=False, size=50000, p=train_probs)out_images = X_train[indices.astype(int)] # this is where I get the error


The following error appears:

TypeError: only integer scalar arrays can be converted to a scalar index with 1D NumPy indices array


This is strange to me because I've already examined the array of indices I've prepared. It's one-dimensional, integer, and scalar.

What am I overlooking?



There are no replies to this topic.

If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.


This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
Protected by Astra Security