如果数组的大小为2x2或更大,则一切正常,但如果行的维度为1,例如1x2,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)