如何将“ tensor([13。,16.]])之类的字符串转换为张量

时间:2019-08-26 14:53:30

标签: python matplotlib

我从txt文件读取了一个数据,其中包含有关位置的信息,如下所示: “ ... 位置:张量([13.,16.]) 位置:张量([11.,1.]) ... ” 我的问题是如何将其转换为实际张量以绘制图。 我正在读取这样的数据:

for line in file:
     M_l = re.search(r"Location: (.*)", line)
     location = M_l.group(1)
     plt.plot(location, 'r+')

1 个答案:

答案 0 :(得分:0)

尝试以下代码段。您必须提取与张量相对应的实际列表(在括号之间),列表为I've been testing the regex by running Logstash locally grok { match => { "resource" => "/[^/]+/[^/]+(/|)(?<repo>[^/]+)?(/%{GREEDYDATA:resource_path})?" } } Test Messages: /list/Lighter-test-group/xyz/123 /list/ /list For messages, /list/Lighter-test-group/xyz/123 gives us repo value as "Lighter-test-group" which is valid /list/ gives us repo value as null which is valid but /list gives repo value as "list" which is an invalid value. The correct value needs to be empty or null. 。因此,使用string将此字符串列表转换为python列表。然后使用ast转换为张量(仅在必要时?)。如果确实要转换为张量,则必须在会话中运行张量并获取值并绘制。如果不需要生成张量,则只需绘制列表即可,而无需使用张量流会话。

tf.convert_to_tensor