【发布时间】:2017-04-10 13:59:10
【问题描述】:
我正在学习如何使用 Graphlab 进行机器学习。所以,我有这个包含四列的数据集 - 有一列“名称”和另一列“评论”。
现在,我想通过产品名称获取特定产品的评论。所以,这就是我尝试过的,但我保留了错误 - ValueError:具有多个元素的数组的真值是不明确的。使用 a.any() 或 a.all()。
if (products['name'] == "Vulli Sophie the Giraffe Teether"):
print (products['review'])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-15-8607777f5c3b> in <module>()
----> 1 if (products['name'] == "Vulli Sophie the Giraffe Teether"):
2 print products['review']
C:\Users\user\Anaconda2\envs\gl-env\lib\site-packages\graphlab\data_structures\sarray.pyc in __nonzero__(self)
752 """
753 # message copied from Numpy
--> 754 raise ValueError("The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()")
755
756 def __bool__(self):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
编辑 -
if (products['name'] == "Vulli Sophie the Giraffe Teether"):
print products['name']
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-16-1be157eebb1a> in <module>()
----> 1 if (products['name'] == "Vulli Sophie the Giraffe Teether"):
2 print products['name']
C:\Users\user\Anaconda2\envs\gl-env\lib\site-packages\graphlab\data_structures\sarray.pyc in __nonzero__(self)
752 """
753 # message copied from Numpy
--> 754 raise ValueError("The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()")
755
756 def __bool__(self):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
【问题讨论】:
-
try : if (products['name'] == "Vulli Sophie the Giraffe Teether"):
-
@MohamedALANI:- 谢谢。仍然出现同样的错误。
-
打印
products['name']并展示给我们。 -
@Jean-FrançoisFabre: - 我已经上传了结果。谢谢。
-
您可能需要为列表“产品”的每个元素执行此操作,这里您似乎正在将字符串列表(或系列)与字符串进行比较。