python中按行和按列的多个矩阵

时间:2018-10-21 11:33:10

标签: python numpy matrix

我想将2个矩阵与row by元素和col by col如下乘以

N = 100; r = [ [0.5] , [0.01] , [0.04] , [0.01] ]; 
x1 = np.random.randn(4,N);
x2 = np.tile(r,(1,N));
x = np.multiply(np.array(x1),np.array(x2));

2个矩阵为4 x 100,当我使用小矩阵进行测试时,结果为true,但是对于大矩阵,我总是得到错误的结果。

x1 = [ [1] , [0.5] , [3] , [0] ];
x2 = [ [2] , [0] , [2] , [3] ];
x = np.multiply(np.array(x1),np.array(x2));
  

结果是:x = [[2],[0],[6],[0]];

非常感谢您的帮助。

0 个答案:

没有答案