How do I consistently flatten a numpy array?

霸气de小男生 提交于 2019-12-01 11:03:52

Stop using matrix. numpy.matrix.flatten returns a 1-row matrix, because that's as flat as matrix instances get. If for some reason you are dead set on using matrix, convert to ndarray with matrix.A before flattening:

flat = whatever_matrix.A.flatten()

or just use A1 to get a flat ndarray directly:

flat = whatever_matrix.A1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!