【问题标题】:Py Operand type(s) for ** or pow(): 'list' and 'int'** 或 pow() 的 Py 操作数类型:'list' 和 'int'
【发布时间】:2022-01-21 05:08:39
【问题描述】:

帮助

只有 numpy 的简单神经网络。代码返回错误

代码

pe = [1,20,-15 ... 23]


learning_rate = 1e-6
#5 generations
for i in range(5):

      #sess = 60 data/12
      while srss <= sess:
              i0 = np.iloc[t][0]
              i1 = np.iloc[t][1]                      
              i2 =  np.iloc[t][2]

              ...
              ...
              i23 =  np.iloc[t][23]

              X = [i0, i1, i2 .... i23]

              y = np.sin(x)

              y_pred = i0 * pe[0] + i1 * pe[1] ...... i23 * pe[23]
              los = np.square(y_pred - y).sum

              If srss == sess:
                 
                   grad_y_pred = 2.0 * (y_pred - y)
                   gred_0 = gred_y_pred.sum()
                   gred_01 = (gred_y_pred * x).sum()
                   gred_02 = (gred_y_pred * x ** 2).sum()

                   gred_23 = (gred_y_pred * x ** 23).sum()                 
                   ....

                   pe[0] -= learning_rate * grad_00
                   pe[1] -= learning_rate * grad_01
                   pe[2] -= learning_rate * grad_01
                   ....
                   pe[23] -= learning_rate * grad_23

              srss = srss + 1

输出

Traceback (most recent call last):
File "run.py", line 124, in <module>
grad_02 = (grad_y_pred * x ** 2).sum()                                    
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'

值类型

  • I1: 124264 INT
  • 输出 Y 类型:5.343
  • 输出 Y_PREAD 总价值 EX:10.24236
  • 损失类型:1.5771358927e+18

更多 我需要一个正确的函数来将 OUTPUT 分类为最高 0.5 或最低 0.5 的值

【问题讨论】:

  • x 是一个列表。你不能取一个列表的指数。
  • x 是一个列表,因此会出现错误。你希望x ** 2 做什么?
  • 也没有定义小写x,只定义了大写但没有使用

标签: python numpy neural-network


【解决方案1】:

尝试将X(或者是x?)转换为numpy数组而不是列表:

X = np.array([i0, i1, i2 .... i23])

【讨论】:

    猜你喜欢
    • 2017-03-27
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    相关资源
    最近更新 更多