请有人能告诉我为什么下面的代码不工作,以及什么是最好的解决办法?
Choices # variable containing True or False in each element.
Choices.shape = (18978,)
BestOption # variable containing 1 or 2 in each element.
BestOption.shape = (18978, 1)
Choices[BestOption==1] # I want to look up the values in choices for all instances where BestOption is 1.
出现以下错误:
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
1条答案
按热度按时间b0zn9rqh1#
BestOption
是一个一维的“列向量”,它实际上是由许多行组成的,被当作二维矩阵来处理。您可以简单地将它重新整形为一维的“行向量”: