Skip to content

Tag: numpy-ndarray

Numpy append 2D array in for loop over rows

I want to append a 2D array created within a for-loop vertically. I tried append method, but this won’t stack vertically (I wan’t to avoid reshaping the result later), and I tried the vstack() function, but this won’t work on an empty array. Does anyone know how to solve this? I can think of…

Numpy condition on a vector rather than an element

I have a numpy array that represents an image, it’s dimensions are (w, h, 4), 4 is for RGBA. Now I want to replace all white pixels with transparent pixels. I wish I could do something like np.where(pic == np.array([255, 255, 255, 255]), np.array([0, 0, 0, 0]), pic) but this exact code obviously doesn&#…