I know, there are plenty of threads about list vs. array but I've got a slightly different problem.
Using Python, I find myself converting between np.array and list quite often as I want to use attributes like
remove, append, extend, sort, index, … for lists
and on the other hand modify the content by things like
*, /, +, -, np.exp(), np.sqrt(), … which only works for arrays.
It must be pretty messy to switch between data types with list(array) and np.asarray(list), I assume. But I just can't think of a proper solution. I don't really want to write a loop every time I want to find and remove something from my array.
Any suggestions?
numpy.deletewill remove items from an array, if that's the only reason you are switching back to a list. See herex = np.arange(5); mask = x>2; print( x[mask] )will print onlyarray([3, 4])without needing to convert to a list.