Issue
I have this numpy array ['[-30,30]' '[-30,30]' '[-30,30]' '[-30,30]'] But I would like to convert it into [[-30,30] [-30,30] [-30,30] [-30,30]]
How can I do that?
Thanks in advance!
Solution
You can use ast.literal_eval
like below:
>>> import ast
>>> lst = np.array(['[-30,30]','[-30,30]','[-30,30]', '[-30,30]'])
>>> type(lst[0])
numpy.str_
>>> type(ast.literal_eval(lst[0]))
list
>>> np.array(list(map(ast.literal_eval, lst)))
array([[-30, 30],
[-30, 30],
[-30, 30],
[-30, 30]])
Answered By - I'mahdi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.