Apr-27-2019, 05:35 AM
Hi all
I have a question about extracting data from a numpy array in an efficient manner. Can anyone help?
The example is simple. I have a numpy array which is an image 100 x 100 pixels. lets call that img. Each pixel in the array has 3 attributes red, green, blue.
So take the first pixel as an example
img[0,0,0] =255 (red pixel)
img[0,0,1] =100 (blue pixel)
img[0,0,2] =0 (green pixel)
Now I want to, without using loops, make a list of array coordinates where a particular condition is met. So let say I want a list of all coordinates where the red pixel value is equal to 255. let's say hypothetically there are 3 pixels that meet this requirement at [0,0], [10,10] and [25,25]. I would want my code to go through the array and generate a new list as follows
newlist = [[0,0],[10,10],[25,25]]
Is there a way to do this in numpy?
Thanks Peter
I have a question about extracting data from a numpy array in an efficient manner. Can anyone help?
The example is simple. I have a numpy array which is an image 100 x 100 pixels. lets call that img. Each pixel in the array has 3 attributes red, green, blue.
So take the first pixel as an example
img[0,0,0] =255 (red pixel)
img[0,0,1] =100 (blue pixel)
img[0,0,2] =0 (green pixel)
Now I want to, without using loops, make a list of array coordinates where a particular condition is met. So let say I want a list of all coordinates where the red pixel value is equal to 255. let's say hypothetically there are 3 pixels that meet this requirement at [0,0], [10,10] and [25,25]. I would want my code to go through the array and generate a new list as follows
newlist = [[0,0],[10,10],[25,25]]
Is there a way to do this in numpy?
Thanks Peter