且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

读取打印的numpy数组

更新时间:2022-12-27 13:17:13

您可以使用re处理字符串,然后使用eval()创建数组:

You can use re to treat the string and then create the array using eval():

 import re
 from ast import literal_eval

 import numpy as np

 a = """[[[ 0 1]
          [ 2 3]]]"""
 a = re.sub(r"([^[])\s+([^]])", r"\1, \2", a)
 a = np.array(literal_eval(a))