Firstly,I have read about this problem
I have a np.array(from a picture)
[[255 255 255 ... 255 255 255]
[255 255 0 ... 255 255 255]
[255 255 255 ... 255 255 255]
...
[255 255 0 ... 0 255 255]
[255 255 0 ... 255 255 255]
[255 255 255 ... 255 255 255]]
I want to delete the row which the amount of 0
is smaller than a specific value.
My code is:
import numpy
from collections import Counter
for i in range(pixelarray.shape[0]):
# Counter(pixelarray[i])[0] represent the amount of 0 in one row.
if Counter(pixelarray[i])[0] < 2: # check the amount of 0,if it is smaller than 2,delete it.
pixelarray = np.delete(pixelarray,i,axis=0) # delete the row
print(pixelarray)
But it raised the error:
Traceback (most recent call last):
File "E:/work/Compile/python/OCR/PictureHandling.py", line 23, in <module>
if Counter(pixelarray[i])[0] <= 1:
IndexError: index 183 is out of bounds for axis 0 with size 183
What should I do?