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

问题描述

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

解决方法

使用eval是最好的解决方案

import numpy as np

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

a = eval(a)