python用符号计算检验多维数组的计算
import sympy as sym
import numpy as np
a111,a112,a121,a122,a211,a212,a221,a222=sym.symbols('a111,a112,a121,a122,a211,a212,a221,a222')
A=[[[a111,a112],\
[a121,a122]],\
[[a211,a212],\
[a221,a222]]]
A=np.array(A)
A1=A[0]
Vector_r=A1[0] #一维数组:行向量
#:[a111 a112]
#print(np.row_stack((Vector_r,)))
#print(np.column_stack((Vector_r,)))
#print(np.row_stack(Vector_r))
Vector_c=Vector_r.reshape(2,1) #改成二维数组:列向量
#:[[a111]
#: [a112]]
print(Vector_c*Vector_r)
#:[[a111**2 a111*a112]
#: [a111*a112 a112**2]]
tt1=np.sum(A,2)
#:[[a111 + a112 a121 + a122]
#: [a211 + a212 a221 + a222]]
tt2_r=np.sum(tt1,1) #按行合并,第2维压缩掉,成一维数组:行向量
#:[a111 + a112 + a121 + a122 a211 + a212 + a221 + a222]
tt2_c=tt2_r.reshape(2,1) #改成二维数组:列向量
#:[[a111 + a112 + a121 + a122]
#: [a211 + a212 + a221 + a222]]
tt3=tt1/tt2_c
#:[[(a111 + a112)/(a111 + a112 + a121 + a122) (a121 + a122)/(a111 + a112 + a121 + a122)]
#: [(a211 + a212)/(a211 + a212 + a221 + a222) (a221 + a222)/(a211 + a212 + a221 + a222)]]
#tt3.T ########二维数组转置,以前的第1维改成列