我想用一个8x8矩阵乘1x1矩阵。显然我知道你不能乘以这两个形状的矩阵。我的问题是如何从1x1矩阵中“提取”数值,以便它相当于将8x8矩阵乘以标量。换句话说,有没有办法将1x1矩阵变成标量?乘以一个单元矩阵
这里是我到目前为止的代码,其中n
是我的1x1矩阵,flux
是我的8×8矩阵:
n=0
for i in range(delta_E.shape[0]):
n+= 100/(210*(Sig_f_cell[i])*flux[i]*delta_E[i]*(1.6022e-13)*V_core)
flux = (np.linalg.inv(L))*G
目标:用n
的值乘以通量看来,n是一个标量,但是当我乘他们,我得到这个错误:
ValueError Traceback (most recent call last)
<ipython-input-26-0df98fb5a138> in <module>()
----> 1 Design_Data (1.34,.037,90)
<ipython-input-25-5ef77d3433bc> in Design_Data(pitch, Pu_fraction, FE_length)
201 print('Number of fuel elements : ',N_FE)
202
--> 203 return n*flux
204
C:\Users\Katey\Anaconda3\lib\site-packages\numpy\matrixlib\defmatrix.py in __mul__(self, other)
341 if isinstance(other, (N.ndarray, list, tuple)) :
342 # This promotes 1-D vectors to row vectors
--> 343 return N.dot(self, asmatrix(other))
344 if isscalar(other) or not hasattr(other, '__rmul__') :
345 return N.dot(self, other)
ValueError: shapes (1,1) and (8,1) not aligned: 1 (dim 1) != 8 (dim 0)
我也尝试过乘以n[0]*flux
和我得到的SAM e错误。
'n'似乎是一个标量而不是矩阵。是什么让你认为它是一个矩阵? – Divakar
@Divakar因为我把它们相乘,它给了我这个 – Katey
@Divakar(见上) – Katey