【发布时间】:2016-01-06 17:52:04
【问题描述】:
我正在尝试使用 numpy 将 2 个向量相乘并进行比较,由于某种原因,它给了我错误。数据来自 CSV 文件 我找到了
The truth value of an array with more than one element is ambigous when trying to index an array
还有更多这种类型的情况,但它与我的情况确实不同.. 我的代码:
import sys
import numpy as np
data = np.loadtxt(sys.argv[1], delimiter = ',')
X = data[:, 1:]
Y = data[:, 0]
#argv[1] is mnist_train_1vs7vs8.csv
wMatrix=(3,len(X[0]))
np.zeros(wMatrix)
for i in range(0,len(Y)):
maxWx=0
for wIndex in range (0,1):
if ( np.dot(wMatrix[wIndex] ,X[i]) < np.dot(wMatrix[wIndex+1],X[i]) ):
maxWx=wIndex+1
它给了我错误:
ValueError: The truth value of an array with more than one element is
ambiguous.
Use a.any() or a.all()`
我只是想将一个向量与一个相同大小的向量相乘,我不明白为什么它不会让我.. 帮助..?
【问题讨论】:
-
错误不是由乘法引起的,而是由比较引起的。您是否尝试过打印出您正在比较的值?
标签: python arrays csv numpy vector