"can't multiply sequence by non-int of type 'list' " python 错误 3

"can't multiply sequence by non-int of type 'list' " error in python 3

在以下代码中 A 初始化后,我一直收到错误 "only 2 non-keyword arguments accepted"。有人可以告诉我出了什么问题或我应该如何解决这个问题吗?这是我用来定义函数的代码:

import numpy as np

A = np.array([10.0, 11.0, 15.0, 17.0, 12.0, 15.0, 18.0, 34.0, 14.0, 12.0, 19.0, 15.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 31.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 20.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 20.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 20.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 25.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0])

B = np.array([0.01, 0.03, 0.05, 0.07, 0.08, 0.10, 0.13, 0.16, 0.20, 0.21, 0.25, 0.30])

def bonus(A,B):
    A = np.array([10.0, 11.0, 15.0, 17.0, 12.0, 15.0, 18.0, 34.0, 14.0, 12.0, 19.0, 15.0],
                 [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
                 [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
                 [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 31.0, 24.0, 25.0, 26.0, 27.0],
                 [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
                 [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 20.0, 25.0, 26.0, 27.0],
                 [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 20.0, 25.0, 26.0, 27.0],
                 [20.0, 20.0, 20.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
                 [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
                 [20.0, 25.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0])

    B = np.array([0.01, 0.03, 0.05, 0.07, 0.08, 0.10, 0.13, 0.16, 0.20, 0.21, 0.25, 0.30])

    C = (A*B)
    return(C)

bonus(A,B)

您忘记在 A 的开头和结尾添加额外的括号。应该是:

A = np.array([[10.0, 11.0, 15.0, 17.0, 12.0, 15.0, 18.0, 34.0, 14.0, 12.0, 19.0, 15.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 31.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 20.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 20.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 20.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 20.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0],
             [20.0, 25.0, 21.0, 23.0, 27.0, 22.0, 25.0, 21.0, 24.0, 25.0, 26.0, 27.0]])