为什么这是有效的:
>>> f = np.array(([[10,20],[11,21],[11,21],[12,22],[13,23]]))
>>> f
array([[10, 20],
[11, 21],
[11, 21],
[12, 22],
[13, 23]])
>>> f.view([('',f.dtype)]*f.shape[1])
array([[(10, 20)],
[(11, 21)],
[(11, 21)],
[(12, 22)],
[(13, 23)]],
dtype=[('f0', '<i8'), ('f1', '<i8')])
但这不会:
>>> f = np.array(([10,11,11,12,13],[20,21,21,22,23])).T
>>> f
array([[10, 20],
[11, 21],
[11, 21],
[12, 22],
[13, 23]])
>>> f.view([('',f.dtype)]*f.shape[1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: new type not compatible with array.