0
roi_pixel_img = crop_img[indices_list]
print (roi_pixel_img)

enter image description here

when i add (I use only to use the entire array (meaning only a part):

np.set_printoptions(threshold=sys.maxsize)

th output is:

enter image description here

the whole part happens in a while loop because I'm extracting pixels in this section, which is irrelevant to the question.

My goal is not to include the lines with [0 255 255] in this array, how can I do that?

the type of roi_pixel_img is numpy.ndarray.

is it even possible to answer this question without an example code for you ?

2
  • What is your array's shape? (roi_pixel_img.shape) Commented Apr 27, 2022 at 17:29
  • its variable, for example (6730, 3). i mean the only variable part that is the first, fixed is 3 Commented Apr 27, 2022 at 17:31

1 Answer 1

1

You can do this by creating an indexing array:

r = (roi_pixel_img == [0,255,255]).all(axis = -1)

roi_pixel_img[~r]

The roi_pixel_img == [0,255,255] statement will result in an array with the same shape as roi_pixel_img (say (N, 3)) and will compare element-wise, eg [0,255,0] will result in [True, True, False]. Using .all(axis = -1) Will reduce along the last axis (in this case axis = 1 would produce the same result) and will result in True if all the element match. So r will have shape (N, ).

Using ~r to index will exclude the matching pixels and due to the shape will be broadcast appropriately by numpy.

Sign up to request clarification or add additional context in comments.

1 Comment

works! could you explain why do you use .all on axis ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.