import numpy as np
survey1 = [[0, 1, 0, 1],
[0, 1, 0, 0],
[1, 0, 0, 1],
[0, 1, 0, 1],
[1, 1, 0, 1]]
survey2 = [[1, 0, 1, 1, 0, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 1, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 1, 1, 1, 0, 1, 1],
[1, 0, 0, 0, 0, 1, 0, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0, 1, 1],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 1, 1, 1, 1, 0, 1, 1],
[0, 0, 1, 1, 1, 1, 0, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1, 0, 1, 1],
[0, 0, 1, 1, 0, 1, 0, 1, 1, 0],
[1, 1, 0, 1, 1, 0, 1, 1, 1, 0],
[0, 0, 0, 1, 0, 1, 0, 0, 0, 1],
[0, 1, 0, 1, 0, 0, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1, 0, 0, 0, 1],
[0, 1, 0, 1, 0, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 1, 1, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]
def makeArray(surveyAnswers):
array = np.array(surveyAnswers)
return array
def calculatePercentage(surveyAnswers):
shapeSurvey = np.shape(makeArray(surveyAnswers))
index_counter = 0
answerArray = makeArray(surveyAnswers)
while index_counter <= shapeSurvey[0]:
currentBrand = answerArray[:,index_counter]
print(currentBrand)
index_counter += 1
calculatePercentage(survey1)
嗨,我必须遍历数组中的每一列,我使用一个计数器,这样我就可以在接下来的每一列中进行循环。但我收到一条错误消息,它指出,对于大小为4的轴1,索引超出了范围。我是新手请帮忙。谢谢您。在
目前没有回答
相关问题 更多 >
编程相关推荐