1 In [41]: a=[1,2,3,4,5,5,6,6,7,8,8,9,9] # list类型数组 2 3 In [42]: b=nu.mean(a) #调用numpy.mean方法计算数组元素的算术平均值 4 In [43]: b 5 Out[43]: 5.615384615384615 6 7 In [44]: b=nu.var(a) # 调用numpy.var方法计算数组元素方差 8 In [45]: b 9 Out[45]: 6.2366863905325447 10 11 12 In [46]: b=nu.diff(a) # diff方法返回相邻数组元素之间差所组成的数组 13 In [48]: b 14 Out[48]: array([1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0]) # 注意返回的是numpy.darray类型 15 16 In [49]: b=nu.std(a) # 调用std方法计算数组元素标准差 17 In [50]: b 18 Out[50]: 2.4973358585766041 19 20 In [53]: b=nu.log(a) # 调用log方法计算元素的对数 21 In [54]: b # 当a数组中元素为收益率时,b则为对数收益率数组 22 Out[54]: 23 array([ 0. , 0.69314718, 1.09861229, 1.38629436, 1.60943791, 24 1.60943791, 1.79175947, 1.79175947, 1.94591015, 2.07944154, 25 2.07944154, 2.19722458, 2.19722458])