这似乎很明显,但它暗指我:我想用numpy.maximum
转换下面的代码,以便在数组上更有效地计算:
P = np.random.uniform(low=-10, high=10, size=(30,))
for i in range(P.shape[0]): #for element in array
print max(P[i], np.ones(P.shape[0])[i], key=abs) #take the absolute max
更有效的版本是使用:
^{pr2}$但是我如何计算这个绝对值,同时保留符号呢?在
使用
np.where
;绝对值作为条件,原始值作为返回元素:相关问题 更多 >
编程相关推荐