The function numpy.array_repr can be used to create a string representation of a NumPy array. How can a string representation of a NumPy array be converted to a Num
numpy.array_repr
eval is the easiest, probably. It evaluates a given string as if it were code.
eval
from numpy import array, all arr_1 = array([1,2,3]) arr_string = repr(arr_1) arr_2 = eval(arr_string) all(arr_1 == arr_2) # True
See also documentation on eval: https://docs.python.org/2/library/functions.html#eval