1 # -*- coding: utf-8 -*- 2 """ 3 Created on Fri Oct 30 15:38:35 2015 4 5 @author: zenwan 6 """ 7 8 import numpy as np 9 import sys 10 reload(sys) 11 sys.setdefaultencoding('utf-8') 12 13 14 ''' 15 数学与统计方法 16 ----------------------------------------- 17 方法 说明 18 ----------------------------------------- 19 sum 对数组的全部或者轴向数据求和 20 mean 算术平均数 21 std,var 标准差,方差 22 min,max 最大值和最小值 23 argmin,argmax 最小元素和最大元素的索引 24 cumsum 所有元素累计求和 25 cumprod 所有元素累计求积 26 ---------------------------------------- 27 ''' 28 arr = np.random.randn(5, 4) # 随机正太分布数据 29 print arr 30 print '数据之和', arr.sum() 31 print '行求和', arr.sum(0) 32 print '列求和s', arr.sum(axis=1) 33 print '均值:', arr.mean() 34 print '行均值:', arr.mean(axis=0) 35 print arr.std() 36 print arr.argmin() 37 print arr.cumsum()
运行结果:
1 [[ 0.10030054 -2.23241737 1.02892048 -0.18729841] 2 [ 1.29873072 0.24527345 -1.22146634 0.46558093] 3 [-0.65625774 -0.87689633 -0.01059515 -1.13711452] 4 [ 2.27650978 -0.83478579 -0.91689558 -1.13587926] 5 [-0.9666233 0.97336183 -1.15523837 -1.33170819]] 6 数据之和 -6.27449861582 7 行求和 [ 2.05266 -2.72546421 -2.27527496 -3.32641945] 8 列求和: [-1.29049475 0.78811876 -2.68086373 -0.61105085 -2.48020803] 9 均值: -0.313724930791 10 行均值: [ 0.410532 -0.54509284 -0.45505499 -0.66528389] 11 1.07395315839 12 1 13 [ 0.10030054 -2.13211683 -1.10319634 -1.29049475 0.00823596 0.25350941 14 -0.96795693 -0.502376 -1.15863373 -2.03553006 -2.04612521 -3.18323973 15 -0.90672995 -1.74151574 -2.65841132 -3.79429058 -4.76091388 -3.78755205 16 -4.94279042 -6.27449862]