python中数组的矩阵乘法

Max*_*091 3 python arrays numpy matrix

我觉得这有点傻,但我似乎无法找到答案

在Numpy中使用数组我希望将3X1数组乘以1X3数组并得到一个3X3数组作为结果,但因为点函数总是将第一个元素视为列向量而第二个元素作为行向量处理我似乎可以"得到它"为了工作,我必须使用矩阵.

A=array([1,2,3])  
print "Amat=",dot(A,A)  
print "A2mat=",dot(A.transpose(),A)  
print "A3mat=",dot(A,A.transpose())  
u2=mat([ux,uy,uz])  
print "u2mat=", u2.transpose()*u2  
Run Code Online (Sandbox Code Playgroud)

产出:

Amat= 14  
A2mat= 14  
A3mat= 14  
u2mat=  
 [[ 0.  0.  0.]  
        [ 0.  0.  0.]  
        [ 0.  0.  1.]]
Run Code Online (Sandbox Code Playgroud)

den*_*nis 7

np.outer 是内置的:

A = array([1,2,3])
print "outer:", np.outer( A, A )
Run Code Online (Sandbox Code Playgroud)

(transpose不起作用,因为A.T与1d数组的A完全相同:

print A.shape, A.T.shape, A[:,np.newaxis].shape
>>> ( (3,), (3,), (3, 1) )
Run Code Online (Sandbox Code Playgroud)

)