我从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+')
答案 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