Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将.predict(x)方法的结果中的元素与另一个数组中的元素匹配并输出?_Python_Arrays_Scikit Learn - Fatal编程技术网

Python 如何将.predict(x)方法的结果中的元素与另一个数组中的元素匹配并输出?

Python 如何将.predict(x)方法的结果中的元素与另一个数组中的元素匹配并输出?,python,arrays,scikit-learn,Python,Arrays,Scikit Learn,我有以下代码: # Load model with open('text_classifier.pkl', 'rb') as f: countVec, model = pickle.load(f) #Convert to bag of words results = countVec.transform(commentsInput) # predict converted text with the trained model predictionsNew = model.predi

我有以下代码:

# Load model
with open('text_classifier.pkl', 'rb') as f:
    countVec, model = pickle.load(f)

#Convert to bag of words
results = countVec.transform(commentsInput)

# predict converted text with the trained model
predictionsNew = model.predict(results)

print(predictionsNew)
printpredictionsNew的输出如下:[[1 0 1 0 1 0]]

当我执行typepredictionsNew时,它将输出的类型返回为numpy.ndarray

该数组中的每个值都对应于数据集中的一个标签,并告诉我输入是否与该标签匹配。例如,假设每个值对应于这个数组标签=['a'、'b'、'c'、'd'、'e'、'f']

我想循环第一个数组和第二个数组,并生成如下输出:

a = 1
b = 0
c = 1
d = 0
e = 1
f = 0
我能做到这一点的最简单方法是什么

更新: 我相信数字数组只包含一个元素。基本上,我想把这个元素分成6个不同的元素,它们对应于我的标签数组。

您正在寻找函数

a=[a,b,c,d,e] b=np.ndarray5,buffer=np.array[0,1,0,1,0],dtype=int 对于zipa中的x,y,b: printf{x}={y} 产出:

a = 0
b = 1
c = 0
d = 1
e = 0

变量名和函数名应在小写字母后面加下划线。你能更具体地说明你在挣扎什么吗?这能回答你的问题吗?是的,很高兴它做到了