python定义整数数组_python – TypeError:只能将整数标量数组转...

我想编写一个函数,从训练集中随机选取元素,但是基于提供的bin概率.我将设置索引除以11个bin,然后为它们创建自定义概率.

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 elements

train_probs.extend([0.001]*(len(X_train) - len(train_probs))) # a small fix to match number of elements

train_probs = train_probs/np.sum(train_probs) # normalize

indices = 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

我收到以下错误:

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

我发现这很奇怪,因为我已经检查了我创建的索引数组,它是1-D,它是整数,它是标量.

我错过了什么?

注意:我试图用astype(int)传递索引.同样的错误.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值