How to convert a Numpy 2D array with object dtype to a regular 2D array of floats

后端 未结 6 1538
太阳男子
太阳男子 2020-12-09 10:02

As part of broader program I am working on, I ended up with object arrays with strings, 3D coordinates and etc all mixed. I know object arrays might not be very favorite in

6条回答
  •  一个人的身影
    2020-12-09 10:49

    This problem usually happens when you have a dataset with different types, usually, dates in the first column or so.

    What I use to do, is to store the date column in a different variable; and take the rest of the "X matrix of features" into X. So I have dates and X, for instance.

    Then I apply the conversion to the X matrix as:

    X = np.array(list(X[:,:]), dtype=np.float)

    Hope to help!

提交回复
热议问题