如果数组的大小为2 x 2或更大,那么一切都很好,但如果行的维数为1,例如1x2,numpy会执行某些操作没想到。当我尝试从一个QString数组创建时,创建一个numpy数组失败了。
我该如何解决这个问题?
# TEST 1 OK
myarray = np.array([[QString('hello'), QString('world')],
[QString('hello'), QString('moon')]],
dtype=object)
print myarray
print myarray.shape
#[[PyQt4.QtCore.QString(u'hello') PyQt4.QtCore.QString(u'world')]
# [PyQt4.QtCore.QString(u'hello') PyQt4.QtCore.QString(u'moon')]]
#(2, 2)
# TEST 2 OK
myarray = np.array([['hello'], ['world']], dtype=object)
print myarray
print myarray.shape
#[['hello']
# ['world']]
#(2, 1)
# TEST 3 FAIL
myarray = np.array([[QString('hello'), QString('world')]], dtype=object)
print myarray
print myarray.shape
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[PyQt4.QtCore.QString(u'h')]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#..
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[PyQt4.QtCore.QString(u'e')]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
# etc...
#(1, 2, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
哦奇怪...似乎像numpy的是处理字符串数组或东西...如果你把会发生什么2个方括号之间的逗号? – karina