如何展平dtype对象的numpy数组 [英] How to flatten a numpy array of dtype object
本文介绍了如何展平dtype对象的numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在截取不同长度的ndarray切片,我希望结果保持平坦. 例如:
I'm taking ndarray slices with different length and I want my result to be flat. For example:
a = np.array(((np.array((1,2)), np.array((1,2,3))), (np.array((1,2)), np.array((1,2,3,4,5,6,7,8)))))
是否有任何直接方法可以通过使用numpy功能(无循环)来使此数组平坦?
Is there any straight way to make this array flat by using numpy functionalities (without loop)?
推荐答案
怎么样:
In [23]: np.hstack(a.flat)
Out[23]: array([1, 2, 1, 2, 3, 1, 2, 1, 2, 3, 4, 5, 6, 7, 8])
这篇关于如何展平dtype对象的numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文