python-3.x - 我想使用 numpy 从以下数组中删除所有 16
解决方案
正如所有评论所述,请添加代码,如果需要,请添加图像。
当您说“删除所有 16 个”时,您的意思是用其他值替换它们还是只选择一个没有 16 个的子数组?
似乎 16 总是放在每行的末尾,因此你可以这样做
img # array containing the 16, of shape (X,Y,4)
img_no16 = img[:,:,:3] # this gets you rid of the last column and returns an array of shape (X,Y,3)
但是,如果您想替换16
数组中的所有元素,您有两个选择
如果它们总是放在每行的末尾,你可以做类似上面的事情
img[:,:,:3] = 0 # or any other number
如果您不知道 16 在哪里并且只想将它们全部替换为 -1,您可以这样做
img[np.where(img == 16)] = -1
推荐阅读
- php - php 使用 strtolower('Fötus') 的奇怪编码行为;
- google-sheets - 跨多个工作表的 Google 工作表查询
- webpack - Webpack 4 - 复制 dub 目录结构
- python - 如何在 Redis 缓存中附加字典?
- python - 解析方法的 Scrapy 参数
- excel - 无法从另一个工作簿复制选择
- php - 在自定义 php 文件中调用 WordPress 内置函数
- python - 绘制 CDF 的平滑曲线
- google-cloud-platform - 如何将图像存储在谷歌云中?
- php - Laravel 选择框,默认显示数据库值