'Turning array specified string into array

I have this spit out from my data acquisition:

data = "[[[array([-9.99999773e-01,  6.74083498e-04]), array([ 9.99999773e-01, -6.74083498e-04])], [array([ 9.99999773e-01, -6.74083498e-04]), array([ 9.99999773e-01, -6.74083498e-04])]]]"

the type of data is string, as I tested.

Is there any way to turn this into array form? For example:

data = [[[np.array([-9.99999773e-01,  6.74083498e-04]), np.array([ 9.99999773e-01, -6.74083498e-04])], [np.array([ 9.99999773e-01, -6.74083498e-04]), np.array([ 9.99999773e-01, -6.74083498e-04])]]]

This worked for my further analysis using python.



Solution 1:[1]

this should work:

exec("data = " + data.replace("array","np.array"))

basically you replace array with np.array and then execute the resulting string as python code

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrCont