Skip to content
Advertisement

How can a string representation of a NumPy array be converted to a NumPy array?

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 NumPy array?

Let’s say the string representation is as follows:

JavaScript

How could this be converted to a NumPy array?

Advertisement

Answer

eval is the easiest, probably. It evaluates a given string as if it were code.

JavaScript

See also documentation on eval: https://docs.python.org/2/library/functions.html#eval

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement