[英]How to subtract a constant from a numpy array and then summing up the results?
How do one subtract a constant from every element in a list and then sum up the result in Python?如何从列表中的每个元素中减去一个常数,然后在 Python 中总结结果? Code attached does not work:
附加代码不起作用:
an_array = np.array([2,4,6,5,8,10])
constant = np.mean(an_array)
result = np.sum(an_array - constant)
np.sum(an_array)-constant*an_array.size
I am a few seconds late as @Qui already pointed this solution out in the comments.我迟到了几秒钟,因为@Qui 已经在评论中指出了这个解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.