【发布时间】:2017-05-10 18:57:30
【问题描述】:
我想将 1x1 矩阵乘以 8x8 矩阵。显然我知道你不能将这两种形状的矩阵相乘。我的问题是如何从 1x1 矩阵中“提取”值,使其相当于将 8x8 矩阵乘以标量。换句话说,有没有办法将 1x1 矩阵变成标量?
到目前为止,这是我的代码,其中n 是我的 1x1 矩阵,flux 是我的 8x8 矩阵:
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 相乘,但我得到了同样的错误。
【问题讨论】:
-
n似乎是标量而不是矩阵。是什么让你认为它是一个矩阵? -
@Divakar 因为当我将它们相乘时,它给了我这个
-
@Divakar(见上文)
-
无法在我的最后重现,也许可以尝试:
n[0]*flux或n[0,0]*flux。 -
@Divakar 谢谢我用另一种方式,谢谢你的帮助
标签: python python-3.x numpy matrix scalar