作为培训课程的一部分,我正在做一个白名单项目。我的程序分为三个部分:白名单、用户的输入和第三个数组,它统计用户输入中出现的白名单单词的实例。所有三个部分都已转换为数组。例如,如果我的whitearray中包含单词(good,ten才,special)和我的用户输入(“我最好的朋友是一个非常好的长笛演奏者。我的好朋友西莉亚没有那么熟练。”),我应该可以打印出一个结果:好2
我的代码:
import numpy
whitefile = open('whitefile.txt', 'r')
check = raw_input("Hi! Please enter a string and we will see which words are in the whitefile! Enter here: ")
elementA = 0
check = check.lower()
loopEr = 0
whiteList = []
for line in whitefile:
myTokens = line.split( )
whiteList.append(myTokens)
inpList = check.split()
whiteArray = numpy.array(whiteList).astype(numpy)
#numpy.reshape(inpArray, (2,3))
inpArray = numpy.array(inpList).astype(numpy)
lenwhitefile = len(whiteList)
whiteListCounter = numpy.zeroes((1, lenwhitefile).dtype = numpy.float64)
for i in range(0, len(inpList)-1):
if inpArray[i] in whiteArray:
while i in range(0, lenwhiteList):
if inpArray[i] == whiteArray[loopEr]:
收到错误:
^{pr2}$我该怎么解决这个问题?在
我认为你有两个问题:
zeros
而不是{,dtype
而不是{whiteListCounter = numpy.zeros((1, lenwhitefile), dtype = numpy.float64)
相关问题 更多 >
编程相关推荐