2 ^( [- z. W. C& V7 W1 j3 k* P生活、生产与科学实验中很多随机变量的概率分布都可以近似地用正态分布来描述。μ决定了其位置,其标准差σ。决定了分布的幅度。当μ = 0,σ = 1时的正态分布是标准正态分布。6 G, N- P+ m) i0 S9 @- a3 _/ d3 R, k
. n- E1 R8 m& |, o k; c: `; ?
标准差如何来?方差是在概率论和统计方差衡量一组数据时离散程度的度量。 " `. c, r, V x3 E 1 r& H. @! a& P4 Z* m其中M为平均值,n为数据总个数,s为标准差,s^2可以理解一个整体为方差。+ c- X: ^9 a6 v+ [/ W2 O
; n+ h% D+ A( G
通过索引切片等获取数组中的值,一维数组示例代码如下:% x8 V/ a" B" W! F" e
2 U/ y- Q/ x, N n( g
二维数组示例代码如下:" r7 F# \: _5 y& A/ G8 j! S
7 t1 w' B0 t' s/ b0 s3 L# o% T' ?
三维数组示例代码如下: * b( X: D8 q# H, D8 J+ n& ?$ W8 s: D6 u$ D& |! k% p; A; B
6 ^+ d# F* }1 r( e4 n4. 数组形状与类型变化 - F; W. j$ }0 S0 C/ t# c3 @ : o) u* `. a/ S; A) y+ |9 S1. ndarray.reshape(shape[, order]) Returns an array containing the same data with a new shape. 示例代码如下: b4 j4 F$ C: L: R
% O! ]5 q8 {+ S, l3 H& h2 O0 k9 v
2. ndarray.resize(new_shape[, refcheck]) Change shape and size of array in-place. 示例代码如下:$ R2 L/ l2 L5 ?3 S" V% c4 O" |; U/ F
1 f1 L5 D- C; C( V# `% B3. 修改类型 ndarray.astype(type) 示例代码如下:! U0 i) Q8 V5 C" T. h* J
1 g* ?* {2 V! Z+ S- N1 }
4. 修改小数位数 ndarray.round(arr, out) Return a with each element rounded to the given number of decimals. 示例代码如下:6 l% t( i: ~+ O) u G
( i# Q4 M3 E. q2 x
5. ndarray.flatten([order]) Return a copy of the array collapsed into one dimension. 示例代码如下: + |+ |9 Q, c0 \ V5 {! c0 P2 u( w - W D; |& ^( }! I+ c8 i1 P3 E" e6. ndarray.T 数组的转置 将数组的行、列进行互换 示例代码如下: ' _1 g$ L" I1 G, x! |$ d* E6 A/ L. t4 `7 V2 `
7. ndarray.tostring([order])或者ndarray.tobytes([order]) Construct Python bytes containing the raw data bytes in the array. 转换成bytes . i- x- w3 x2 i T) |1 r c9 q* y; p2 @% {8. ndarray.copy([order]) Return a copy of the array. 当我们不想修改某个数据的时候,就可以去进行拷贝操作。在拷贝的数据上进行操作,示例代码如下:( K# C6 v( Z# ]( \; |7 s
! D+ Y. q, S" D$ Q7 A: ]7 x' X+ i' ^( J" f( \7 q0 }
4. 数组运算0 i, n9 O/ } b" c
. L" E" ^6 y% c- K" m
4.1 逻辑运算 4 X$ E! s& a5 _' {- U. `9 U3 c7 e0 L' q$ m
1 g3 q6 Q& G' V2 [4 ~' H( J/ N7 A
通用判断函数,np.all(),示例代码如下:/ ? R- N! E0 t2 ?- H2 R
1 L: K) b$ |6 W# I: l+ D
np.unique():返回新的数组的数值,不存在重复的值,示例代码如下:9 }5 G, L% z2 @
& l6 b) P# p: j8 ~# Hnp.where (三元运算符):通过使用np.where能够进行更加复杂的运算,示例代码如下:* d' }3 V" D* G2 G& Z6 ?3 `- m
* H- j6 I5 U& F' e7 s$ Q7 ~ ?# y
4.2 统计运算 ; U o. p0 H' ]* u8 P( |& d# a7 T. f1 s. C, F/ D
在数据挖掘/机器学习领域,统计指标的值也是我们分析问题的一种方式。注意:进行统计的时候,axis轴 的取值并不一定, NumPy中不同的API轴的值都不一样,在这里,axis 0代表列, axis 1代表行 去进行统计。常用的指标如下:9 C y: {0 N$ F! q
! x; X5 Z4 a9 b: `; U7 emin(a[, axis, out, keepdims]) Return the minimum of an array or minimum along an axis. 示例代码如下:7 ]/ M+ f3 l& }8 s) d9 c0 |$ y$ Z
8 a. X. x5 Z1 Smax(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis. 示例代码如下:2 e5 c. O$ n6 i& J4 b& O
( g* w2 j) I: z( X1 t( L+ Fmedian(a[, axis, out, overwrite_input, keepdims]) Compute the median along the specified axis. 示例代码如下: # ?: n# A, l1 L* C: p k* `( d+ n( y- z! j
mean(a[, axis, dtype, out, keepdims]) Compute the arithmetic mean along the specified axis. 示例代码如下: , ~9 B4 o: V: Y9 k/ n 5 O# U1 A: ^0 @3 V$ Pstd(a[, axis, dtype, out, ddof, keepdims]) Compute the standard deviation along the specified axis. 示例代码如下:5 `4 i a) q1 G/ Y- Y8 J
" i3 Y8 B a O/ ?# ovar(a[, axis, dtype, out, ddof, keepdims]) Compute the variance along the specified axis. 示例代码如下: ) X2 e3 k, N r' g4 }; H' J! p6 |/ ^
np.argmax(temp, axis=) 示例代码如下: 7 r$ L: a7 k5 D9 P' O% x. R. C, N) s
np.argmin(temp, axis=) 示例代码如下:1 y$ V, d% ]2 u# n0 @) ~
4 Q! E, Y" f. @& x, k: M! r( m& @4.3 数组间运算 + }0 K& |2 V. F" ^! \& ?, j P- z& V/ o' m) V
数组与数的运算,示例代码如下: " S* n% ]" @; W1 l* J) ^# P, v , D' h* l+ M' H8 P+ n4 t矩阵运算,什么是矩阵?矩阵,英文matrix,和array的区别矩阵必须是2维的,但是array可以是多维的。示例代码如下: 2 ]) T/ A1 z7 W& t" c4 i2 _% I& z4 [4 V