VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • 数据分析和科学计算可视化(6)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
矩阵不同维度上的计算
 
>>> x = np.matrix(np.arange(0,10).reshape(2,5))  # 二维矩阵
>>> x
matrix([[01234],
        [56789]])
>>> x.sum()                                      # 所有元素之和
45
>>> x.sum(axis=0)                                # 纵向求和
matrix([[ 5,  7,  91113]])
>>> x.sum(axis=1)                                # 横向求和
matrix([[10],
        [35]])
>>> x.mean()                                     # 平均值
4.5
>>> x.mean(axis=1)
matrix([[ 2.],
        7.]])
>>> x.mean(axis=0)
matrix([[ 2.5,  3.5,  4.5,  5.5,  6.5]])
 
>>> x.max()                                # 所有元素最大值
9
>>> x.max(axis=0)                          # 纵向最大值
matrix([[56789]])
>>> x.max(axis=1)                          # 横向最大值
matrix([[4],
        [9]])
>>> weight = [0.30.7]                    # 权重
>>> np.average(x, axis=0, weights=weight)
matrix([[ 3.5,  4.5,  5.5,  6.5,  7.5]])
 
>>> x = np.matrix(np.random.randint(010, size=(3,3)))
>>> x
matrix([[374],
        [518],
        [270]])
>>> x.std()                         # 标准差
2.6851213274654606
>>> x.std(axis=1)                   # 横向标准差
matrix([[ 1.69967317],
        2.86744176],
        2.94392029]])
>>> x.std(axis=0)                   # 纵向标准差
matrix([[ 1.24721913,  2.82842712,  3.26598632]])
>>> x.var(axis=0)                   # 纵向方差
matrix([[  1.55555556,   8.        ,  10.66666667]])

相关教程