如何将(4,3)数组转换为(4,1)数组?

myarray = array([[1,2,3],[0,1,2]])
myarray.shape = (4,3)

结果应如下所示:

MUTAG_graph_struct[0][0]
Out[112]: 
(array([[0,0],[1,1],0]],dtype=uint8),array([[(array([[ 5],[22],[ 5],[20]],)]],dtype=[('values','O')]),array([[array([[2]],dtype=uint8)],[array([[1,3,4,5]],[array([[2]],dtype=uint8)]],dtype=object))

result = MUTAG_graph_struct[0][0][2]

所以在我的情况下,我想要像上面那样输出。一个带有数组元素的数组。 然后应该给出:

输出:MUTAG_graph_struct[0][0][2]

array([[array([[1,3]],[array([[0,2]],dtype=object)

您能建议怎么做吗? 我正在使用python3。

我尝试了np.stacknp.concatenate,但无法解决问题吗?

since1129 回答:如何将(4,3)数组转换为(4,1)数组?

您的预期输出没有正确的包围。如果ypu看起来像

array([[[[1,2,3]]],[[[0,1,2]]]])

您可以尝试进行myarray.reshape(4,3)

本文链接:https://www.f2er.com/3160913.html

大家都在问