[英]retreive array value from text file and post it in array python
hello First i'm new on python What i want is to retreive from text file that containts set of array values : 你好,首先我是python的新手,我想要从包含数组值集合的文本文件中检索:
This is my text files: 这是我的文本文件:
[0 1]
[1 0]
[1 1]
[0 1] ....
i want to get an array that contains only the axes one 我想得到一个只包含一个轴的数组
[[1],[0],[1],[1]]
and transofrm it to a vector : 并将其转换为向量:
[ 1,0,1,1]
i did this code and it does not work 我做了这段代码,它不起作用
file = open('Score.txt','r')
for i in file:
y_true = np.argmax(i, axis=1).transpose()
print(y_true)
Here's how I'd get the second axis as a list, then you can do whatever you want with it. 这是我将第二个轴作为列表的方式,然后您可以使用它进行任何操作。 Assuming your example is the format for all data
假设您的示例是所有数据的格式
with open(r"Score.txt", "r") as f:
lines = f.readlines()
res = [int(x.split()[1].replace("]","")) for x in lines]
>>> res
[1, 0, 1, 1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.