NumPy 中是否有一种简单的方法来展平类型对象数组?
我知道 .flatten() 方法会展平由相同大小的数组构造的非对象类型数组:
I1 a = np.array([[1],[2],[3]])
I2 a.flatten()
O2 array([1, 2, 3])
但是,我无法将 dtype=object 数组展平:
I4 b
O4 array([[1], [2, 3], [3]], dtype=object)
I5 b.flatten()
O5 array([[1], [2, 3], [3]], dtype=object)
谢谢。
最佳答案
如果你想要 [1,2,3,3],试试这个然后
np.hstack(b)
关于python - 压平numpy数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11367243/