【发布时间】:2021-03-21 15:08:18
【问题描述】:
我是 numpy 新手,这行代码有问题。我正在尝试从一组最终分数中制作一组字母等级,但不断遇到以下错误消息:
具有多个元素的数组的真值是不明确的。使用 a.any() 或 a.all()
import numpy as np
def letterGrade(score):
#returns corresponding letter grade for given numerical score
grade = 'unknown'
if score >= 93 and score <= 100:
grade = 'A'
elif score >= 90 and score <= 92.99:
grade = 'A-'
elif score >= 86 and score <= 89.99:
grade = 'B+'
elif score >= 83 and score <= 85.99:
grade = 'B'
elif score >= 80 and score <= 82.99:
grade = 'B-'
elif score >= 76 and score <= 79.99:
grade = 'C+'
elif score >= 73 and score <= 75.99:
grade = 'C'
elif score >= 70 and score <= 72.99:
grade = 'C-'
elif score >= 66 and score <= 69.99:
grade = 'D+'
elif score >= 60 and score <= 65.99:
grade = 'D'
elif score >= 0 and score <= 59.99:
grade = 'F'
elif score < 0 or score > 100:
grade = 'can not be determined from the input given'
return grade
def main():
score_headings = np.load("C:/Users/Javy/Downloads/score_headings.npy")
total = score_headings[:,1:].sum(axis=1)
total = np.array(total)
ltrGrd = letterGrade(total)
main()
【问题讨论】: