2021年3月21日星期日

How to remove all string elements from a numpy object array

origin array is like:

array([nan, nan, 'hello', ..., nan, 'N', 61.0], dtype=object)  

How can I remove all string from this array and get a new array with dtype float?

I know I can do this using python list:

[i for i in x if type(i) == float]  

but this way will change numpy.ndarray to list, is there a way to do this in numpy?

https://stackoverflow.com/questions/66739758/how-to-remove-all-string-elements-from-a-numpy-object-array March 22, 2021 at 10:55AM

没有评论:

发表评论