SyntaxError: keyword can't be an expression with np.zeroes

SyntaxError: keyword can't be an expression with np.zeroes

作为培训课程的一部分,我正在从事白名单项目。我的程序分为三个部分:白名单、用户输入和第三个数组,该数组计算用户输入中出现白名单单词的实例。所有三个部分都已转换为数组。例如,如果我的 whitearray 包含单词 (good, talented, special) 和我的用户输入 ("My best friend is a really good flute player. My good friend Celia isn't as skillful."),我应该能够打印结果:good 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]:

收到错误:

File "whitelist.py", line 21
whiteListCounter = numpy.zeroes((1, lenwhitefile).dtype = numpy.float64)
SyntaxError: keyword can't be an expression

我该如何解决这个问题?

我认为您有 2 个问题:

  1. zeros 而不是 zeroes
  2. ,dtype 而不是 .dtype

whiteListCounter = numpy.zeros((1, lenwhitefile), dtype = numpy.float64)