关于layers中matmul做运算的疑问
Created by: jinyuKING
环境:paddle-1.4.1 python3.6.5 cpu 问题:打算做两个一维矩阵的乘法计算,使用numpy自带函数np.matmul()做计算可以直接得出结果,代码如下: import numpy as np a=[1,2,3,4] b=[4,3,2,1] result=np.matmul(a,b) print(result) 使用fluid.layers中的matmul()计算出现报错,请问需要怎么修改,感觉官网的这个op的解释看不明白,代码如下: import paddle.fluid as fluid import numpy as np a = fluid.layers.create_tensor(dtype='int64', name='a') b = fluid.layers.create_tensor(dtype='int64', name='b') y = fluid.layers.matmul(a,b) place = fluid.CPUPlace() exe = fluid.executor.Executor(place) exe.run(fluid.default_startup_program()) a1 = np.array([1,2,3,4]).astype('int64') b1 = np.array([4,3,2,1]).astype('int64') result = exe.run(program=fluid.default_main_program(), feed={'a': a1, 'b': b1}, fetch_list=[y]) print(result) 报错信息: y = fluid.layers.matmul(a,b) File "E:\anaconda\lib\site-packages\paddle\fluid\layers\nn.py", line 4925, in matmul __check_input(x, y) File "E:\anaconda\lib\site-packages\paddle\fluid\layers\nn.py", line 4912, in __check_input if x_shape[-1] != y_shape[-2]: IndexError: list index out of range