Skip to content

Tag: numpy

How to expand / dilate a numpy array?

I’m performing a image analysis and generated seeds in the form of a boolean array : As I want to do a subsequent analysis on the area surrounding the True value, I want to expand it (by a certain number, say pixels). This would result in the following: Is there any function or simple way of solving my …

How do you produce a random 0 or 1 with random.rand

I’m trying to produce a 0 or 1 with numpy’s random.rand. np.random.rand() produces a random float between 0 and 1 but not just a 0 or a 1. Thank you. Answer You can use np.random.choice with a list of [0,1], or use np.random.radint with a range of 0,2 You can also use the random module for the equ…

Numpy Zero Padding to match a certain shape

I have a file with arrays or different shapes. I want to zeropad all the array to match the largest shape. The largest shape is (93,13). To test this I have the following code: how can I zero pad this array to match the shape of (93,13)? And ultimately, how can I do it for thousands of rows? Edit: The