I have a numpy array with a single value (scalar) which I would like to convert to correspoding Python data type. For example:
import numpy as np
a = np.array(3)
b = np.array('3')
I could convert them to int
and str
by casting:
a_int = int(a)
b_str = str(b)
but I need to know the types in advance. I would like to convert a
to an integer and b
to a string without explicit type checking. Is there a simple way to achieve it?