Quantcast
Viewing all articles
Browse latest Browse all 14040

How to remove integers from a mixed numpy array containing sub-arrays and integers?

I have a numpy array that contains both sub-arrays and an integer:

mixed_array = np.array([np.array([1, 2]), np.array([1, 2]), 0])

I want to mask the array so that I am left with only the sub-arrays and not the integer.

mixed_array = np.array([np.array([1, 2]), np.array([1, 2]))

I am working with very large arrays so I can't afford to use loops.

I have tried indexing in various ways on ~is_instance() and .dtype attributes. The mixed array is created by a useful package function, so it's hard to avoid creating it.

Edit: would it be possible to convert the ints to arrays (such as: np.array([0]) for the example above?


Viewing all articles
Browse latest Browse all 14040

Trending Articles