Skip to content
Advertisement

Tag: numpy

Dataframe how to update a column based many str values

I am creating a small financial management program which imports my transactions from CSV into Python. I want to assign values to a new column ‘category’ based on strings found in the ‘details’ column. I can do it for one, but my question is how do I do it if I had a huge list of possible strings? For example

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 ‘radial expansion’

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 equivalent of these

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

Advertisement