码迷,mamicode.com
首页 > 其他好文 > 详细

numpy加权平均

时间:2017-04-13 17:57:31      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:nump   code   元素   axis   imp   span   1.5   blog   logs   

1 import numpy as np
2 a = np.arange(15).reshape(3,5)
3 a

array([[ 0, 1, 2, 3, 4],
      [ 5, 6, 7, 8, 9],
      [10, 11, 12, 13, 14]])

np.average(a, axis=0,weights=(10, 5, 1))

array([ 2.1875,  3.1875,  4.1875,  5.1875,  6.1875])

axis=0 对最外层维度元素计算, weights=(10, 5, 1) 给投的权重分别为10 ,5 , 1

[ 2.1875,  3.1875,  4.1875,  5.1875,  6.1875]  =  ( 10*[ 0, 1, 2, 3, 4] + 5*[ 5, 6, 7, 8, 9] + 1*[10, 11, 12, 13, 14]) / (10+5+1)

 

numpy加权平均

标签:nump   code   元素   axis   imp   span   1.5   blog   logs   

原文地址:http://www.cnblogs.com/cymwill/p/6705001.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!