Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?)

简介: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?)

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 368)image.png在网上搜说是版本高了,不可以,试了好久,就差把所有的版本都下下来试试了,然后偶然想到,是不是类型错了。于是就断点调试一步步网上调试。他不是直接和你说这句话有问题,而是拐弯抹角的和你说,就是很烦。最后在**input_ques = [input_ques.toarray()][0]**发现了错误,你见过toarray()外面的括号是列表形式的???

恍然大悟,括号(可以理解为元组)写成列表([])了。


我的代码如下:

ate_question
# todo  计算输入问题和列表之间的相似度并选出最大相似度的索引
def get_similar_index(input_ques, questions):
    score = []
    input_ques = (input_ques.toarray())[0]
    for qustion in questions:
        qustion = qustion.toarray()
        num = float(np.matmul(qustion, input_ques))
        # print(num)
        demo = np.linalg.norm(qustion) * np.linalg.norm(input_ques)
        cos = num / (demo + 1e-3)
        score.append(cos)
    if max(score) < 0.1:
        print("亲,对不起,本FAQ中暂时还没有收录你所提到的问题,我们将会继续改进!")
    else:
        best_index = score.index(max(score))
        return best_index
if __name__ == '__main__':
    # todo 获取问题列表和答案列表冰进行预处理
    # todo 获取问题和列表   这里建议问题和答案放在一行,不然会一个答案出现问题(缺失),后面的答案会乱序
    questions = read_corpus("./data/questions.txt")
    answers = read_corpus("./data/answers.txt")
    # todo 对问题列表进行预处理
    questions_list = get_questions(questions)
    print("亲,欢迎使用FAQ智能问答系统")
    while True:
        print("")
        input_ques = input("请输入你所需要询问的问题:\n")
        if input_ques.upper() == "Q":
            print("觉得有帮助可以来个三连!")
            break
        else:
            # todo  处理输入的问题
            question_process = solove_questions(questions_list, input_ques)
            # todo  获取最大问题相似度的索引并给出相应的答案
            print("亲,正在寻找答案,请耐心等待")
            answer_index = get_similar_index(question_process[-1], question_process[0:-1])
            if answer_index is not None:
                print("亲,我们为你找到的答案如下:\n", answers[answer_index])
                print("亲,你可能还想了解这些问题", questions[answer_index])

结果:image.png






目录
相关文章
|
算法 C# C++
HALCON error #1201: Wrong type of control parameter: 1 in operator threshold
HALCON error #1201: Wrong type of control parameter: 1 in operator threshold
|
7月前
|
前端开发
Google Earth Engine(GEE)——argument ‘input‘: Invalid type. Expected type: Image<unknown bands>错误
Google Earth Engine(GEE)——argument ‘input‘: Invalid type. Expected type: Image<unknown bands>错误
82 0
|
数据库
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
1198 0
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
|
机器学习/深度学习 PyTorch 算法框架/工具
解决Pytorch中RuntimeError: expected scalar type Double but found Float
解决Pytorch中RuntimeError: expected scalar type Double but found Float
2730 0
|
XML 数据格式
XML问题: The processing instruction target matching &quot;[xX][mM][lL]&quot; is not allowed
XML问题: The processing instruction target matching &quot;[xX][mM][lL]&quot; is not allowed
212 0
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
472 0
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
334 0
|
计算机视觉
opencv出错:error: (-213:The function/feature is not implemented) Unknown/unsupported array type
opencv出错:error: (-213:The function/feature is not implemented) Unknown/unsupported array type
477 0
|
存储 JSON Linux
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (ch
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (ch
|
关系型数据库 MySQL 数据库
当你遇到Error: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value:
当你遇到Error: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value: