Suppose I have a NumPy structured array with various numeric datatypes. As a basic example,
my_data = np.array( [(17, 182.1), (19, 175.6)], dtype=\'i2,f4\
The obvious way works:
>>> my_data
array([(17, 182.10000610351562), (19, 175.60000610351562)],
dtype=[('f0', '>> n = len(my_data.dtype.names) # n == 2
>>> my_data.astype(','.join(['f4']*n))
array([(17.0, 182.10000610351562), (19.0, 175.60000610351562)],
dtype=[('f0', '>> my_data.astype(','.join(['f4']*n)).view('f4')
array([ 17. , 182.1000061, 19. , 175.6000061], dtype=float32)
>>> my_data.astype(','.join(['f4']*n)).view('f4').reshape(-1, n)
array([[ 17. , 182.1000061],
[ 19. , 175.6000061]], dtype=float32)