我做了一个dtype是:
mytype = np.dtype([('a',np.uint8), ('b',np.uint8), ('c',np.uint8)])
所以使用这个dtype的数组:
test1 = np.zeros(3, dtype=mytype)
测试1是:
array([(0, 0, 0), (0, 0, 0), (0, 0, 0)],
dtype=[('a', '|u1'), ('b', '|u1'), ('c', '|u1')])
现在我有test2:
test2 = np.array([[1,2,3], [4,5,6], [7,8,9]])
当我使用test2.astype(mytype)
时,结果不是我想要的:
array([[(1, 1, 1), (2, 2, 2), (3, 3, 3)],
[(4, 4, 4), (5, 5, 5), (6, 6, 6)],
[(7, 7, 7), (8, 8, 8), (9, 9, 9)]],
dtype=[('a', '|u1'), ('b', '|u1'), ('c', '|u1')])
我希望结果是:
array([(1, 2, 3), (4, 5, 6), (7, 8, 9)],
dtype=[('a', '|u1'), ('b', '|u1'), ('c', '|u1')])
有什么办法吗?谢谢。