如何用Python中的原始元素用Python中的向量对矩阵列进行取幂

时间:2018-03-27 13:57:20

标签: python matlab numpy matrix

我正在使用numpy将代码从MATLAB转换为Python。但是,我遇到了一个指数,它给了我一个

ValueError: could not broadcast input array from shape (40,40) into shape (40)

这是一个可重现的问题

import numpy as np
a = np.arange(1240).reshape(40, 31)
b = np.ones(a.shape)
c = np.ones((40, 1))

我想要的计算:

for n in range(31):
    b[:, n] = a[:, n] ** c

原始MATLAB代码

for n=1:1:N
cp(:,n) = c(:,n).^(T);
end

T是40,1基质,cp和c是31,40基质

此外,如果有任何Pythonic方法,请告诉我。

0 个答案:

没有答案