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')
How can I cast this into a regular NumPy array of floats?
From this answer, I know I could use
np.array(my_data.tolist())
but apparently it is slow since you "convert an efficiently packed NumPy array to a regular Python list".
You can do it easily with Pandas:
>>> import pandas as pd
>>> pd.DataFrame(my_data).values
array([[ 17. , 182.1000061],
[ 19. , 175.6000061]], dtype=float32)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With