如何解决“只能将整数标量数组转换为标量索引”

2024-09-27 22:31:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我收到一个奇怪的错误,代码如下:

import numpy as np
w=np.random.rand(100,10)
x=np.random.rand(200,100)
y= np.random.rand(200,10)

def compute( x, y):
    numpy_x = np.array(x) 
    numpy_y = np.array(y)

    zeross = np.zeros(np.shape(x)[0])
    oness = np.ones(np.shape(x)[0])

    result= np.zeros((np.shape(x)[0],np.shape(y)[1]))
    for i in range(np.shape(x)[1]):
        for j in range(np.shape(y)[1]):
            result[i,j] = w[i,j]+np.max(zeross, np.subtract(oness,w[:,j].dot(np.transpose(numpy_x)))).dot(numpy_x[:,i]*(numpy_y[:,j]*-1))

    return result

print(compute(x,y))

这里x100 by 100矩阵,y100 by 5矩阵{}是{}矩阵 我得到的错误是:

Test Failed: only integer scalar arrays can be converted to a scalar index

编译器似乎指示错误在库中?在

^{pr2}$

请帮忙


Tags: innumpyfor错误npzeros矩阵random

热门问题