I get a weird error with following codes:
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))
Here x
is a 100 by 100
matrix, y
is a 100 by 5
matrix w
is a 100 by 5
matrix
The error that I'm getting is :
Test Failed: only integer scalar arrays can be converted to a scalar index
The compiler seems to indicate error is in library?
37 return result
38
---> 39 print(compute(x,y))
2 frames
<ipython-input-36-8b5bccb531cc> in compute(x, y)
33 for i in range(np.shape(x)[1]):
34 for j in range(np.shape(y)[1]):
---> 35 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))
36
37 return result
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in amax(a, axis, out, keepdims, initial)
2503 """
2504 return _wrapreduction(a, np.maximum, 'max', axis, None, out, keepdims=keepdims,
-> 2505 initial=initial)
2506
2507
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
84 return reduction(axis=axis, out=out, **passkwargs)
85
---> 86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
87
88
Please help