Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16536

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

$
0
0

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 16536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>