将字符串转换为数组的numpy数组

时间:2020-09-01 00:04:49

标签: python numpy numpy-ndarray string-literals

我有一个numpy数组的字符串表示形式。如何从这种格式转换为数组数组?

1 个答案:

答案 0 :(得分:0)

使用eval是最好的解决方案

import numpy as np

a = "np.array([[1,2],[2,3]])"

a = eval(a)