您使用以下代码行:
reduce(np.multiply, np.ix_(*vs))
np.ix_()将进行外部广播,您需要减少,但是您可以传递
np.multiply不带lambda函数的ufunc 。
比较如下:
import numpy as npvs = [np.r_[1,2,3.0],np.r_[4,5.0],np.r_[6,7,8.0]]shape = map(len, vs) # specify the orientation of each vectornewshapes = np.diag(np.array(shape)-1)+1reshaped = [x.reshape(y) for x,y in zip(vs, newshapes)]# direct productA = reduce(lambda a,b: a*b, reshaped, 1)B = reduce(np.multiply, np.ix_(*vs))np.all(A==B)
重用:
True



