Python矩阵乘法; numpy数组

tha*_*ing 2 python arrays numpy matrix

我有矩阵乘法的一些问题:

我想要乘以例如a和b:

a=array([1,3])                     # a is random and is array!!! (I have no impact on that)
                                     # there is a just for example what I want to do...

b=[[[1], [2]],                     #b is also random but always size(b)=  even 
   [[3], [2]], 
   [[4], [6]],
   [[2], [3]]]
Run Code Online (Sandbox Code Playgroud)

所以我想要的是以这种方式成倍增长

[1,3]*[1;2]=7
[1,3]*[3;2]=9
[1,3]*[4;6]=22
[1,3]*[2;3]=11
Run Code Online (Sandbox Code Playgroud)

所以我需要的结果是:

x1=[7,9]
x2=[22,8]
Run Code Online (Sandbox Code Playgroud)

我知道非常复杂,但我尝试了2个小时来实现这个但没有成功:(

eat*_*eat 7

b似乎有一个不必要的维度.

适当的b你可以使用dot(.),如:

In []: a
Out[]: array([1, 3])
In []: b
Out[]:
array([[1, 2],
       [3, 2],
       [4, 6],
       [2, 3]])
In []: dot(b, a).reshape((2, -1))
Out[]:
array([[ 7,  9],
       [22, 11]])
Run Code Online (Sandbox Code Playgroud)