Skip to content
Advertisement

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 the following solution: Is there a

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’t work: pic == something compares every

How to convert nested numpy arrays in a dictionary to JSON?

I’m parsing nested dictionaries, which have different degrees of how nested they are (dictionaries within dictionaries within dictionaries, etc.) I do not know beforehand to what degree the dictionaries are nested. The problem is, certain dictionary values are numpy.ndarrays. When I try to write the dictionary my_dictionary to JSON with I will get the following error: Naturally, one way to

Loading the binary data to a NumPy array

I am having trouble reading the binary file. I have a NumPy array as, I wrote this array to a file in binary format. Now, I am unable to get back the data from the saved binary file. I tried using numpy.fromfile() but it didn’t work out for me. When I printed the data I got [0.00000000e+00 2.19335211e-13 8.33400000e+04 …

Advertisement