convert unicode array to numpy
numpy, python, unicode
Solution
You could use literal_eval
from ast import literal_eval
import numpy as np
s=u'[(12520, 12540), (16600, 16620)]'
arr= np.array(literal_eval(s))
Problem
I have arrays of unicode strings like this ``` u'[(12520, 12540), (16600, 16620)]' ``` and need to convert these to numpy arrays. A similar question treats the problem of already having an array with unicode elements, but in my case the brackets are part of the string. Is there a way of directly converting this to a numpy array (of ints) without having to manually remove the brackets?