python布尔型索引,python - 布尔值作为索引的Python效果(a [a == 0] = 1) - SO中文参考 - www.soinside.com...

我目前正在实现一些我在github上看到的代码。

这里的兴趣点如下:def prepro(I):

""" prepro 210x160x3 uint8 frame into 6400 (80x80) 1D

float vector """

I = I[35:195] # crop

I = I[::2,::2,0] # downsample by factor of 2

I[I == 144] = 0 # erase background (background type 1)

I[I == 109] = 0 # erase background (background type 2)

I[I != 0] = 1 # everything else (paddles, ball) just set to 1

return I.astype(np.float).ravel()

作者在这里对图像进行预处理,以训练神经网络。我感到困惑的部分是:I[I == 144] = 0 # erase background (background type 1)

I[I == 109] = 0 # erase background (background type 2)

I[I != 0] = 1 # everything else (paddles, ball) just set

我认为作者希望将列表中具有值144(109,而不是0)的所有元素设置为特定值。但是,如果我是对的,则布尔值在python中仅代表0或1。因此,将列表与整数进行比较将始终为False,因此为0。

这使I[I==x] <=> I[0] : x is integer为何还要这样做呢?

我在这里想念什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值