我有一个像这样的对象数组

array([array([[2.4567]],dtype=object), array([[3.4567]],dtype=object), array([[4.4567]],dtype=object), array([[5.4567]],dtype=object) ... array([[6.4567]],dtype=object))

这只是一个例子,实际的例子要大得多。
那么,如何将其转换为一个普通的浮点数数组。

最佳答案

使用numpy.concatenate

>>> arr = array([array([[2.4567]],dtype=object),array([[3.4567]],dtype=object),array([[4.4567]],dtype=object),array([[5.4567]],dtype=object),array([[6.4567]], dtype=object)])
>>> np.concatenate(arr).astype(None)
array([[ 2.4567],
       [ 3.4567],
       [ 4.4567],
       [ 5.4567],
       [ 6.4567]])

08-24 14:07