Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我想使用numpy从以下数组中删除所有16个_Python 3.x_Numpy - Fatal编程技术网

Python 3.x 我想使用numpy从以下数组中删除所有16个

Python 3.x 我想使用numpy从以下数组中删除所有16个,python-3.x,numpy,Python 3.x,Numpy,我想使用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


我想使用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#或任何其他数字

  • 如果你不知道16个在哪里,只想用-1来替换它们,你可以这样做
    img[np.where(img==16)]=-1


  • 数组在图像中附加为“在此处输入图像描述”您尝试了什么?您可以添加任何不起作用的代码示例吗?-请显示您尝试了什么以及失败了什么。关于我为什么投反对票的更多信息,请参阅链接:)将图像作为代码发布并不是提问的最佳方式。添加代码,为了更清晰,如果需要,也可以添加图像。共享您的代码