& x0 M, @6 O! g8 C生活、生产与科学实验中很多随机变量的概率分布都可以近似地用正态分布来描述。μ决定了其位置,其标准差σ。决定了分布的幅度。当μ = 0,σ = 1时的正态分布是标准正态分布。, u* }) q) o% ^0 q/ Z
3 z0 U5 S. `* r' U4 i+ L
标准差如何来?方差是在概率论和统计方差衡量一组数据时离散程度的度量。 3 G5 D* t t t) g3 Q5 ~! C6 h+ S9 A' ?2 \6 v& i: A
其中M为平均值,n为数据总个数,s为标准差,s^2可以理解一个整体为方差。 3 G2 f' ~' @" B' @" k9 a5 z $ u& c" q- `0 T: ~7 y通过索引切片等获取数组中的值,一维数组示例代码如下:# B( i; x8 b8 p6 a' U
2 D3 e9 v* A2 N- R9 i% m% r' c2 s
二维数组示例代码如下: ' x# t" f7 U$ y; @9 B5 b% b1 @6 ~5 B+ k& E8 ^' ^, W3 x: U
三维数组示例代码如下: 4 |* R+ k+ y. L 9 t9 m2 H- G; [3 p1 B6 U; N1 m4 ^# K7 }1 p" ]0 C( n
4. 数组形状与类型变化 3 m, A& m! }" g9 D/ h, Q ' y" r9 m o8 h9 ^1. ndarray.reshape(shape[, order]) Returns an array containing the same data with a new shape. 示例代码如下: 4 ?3 j7 l) N! \ , Z6 [) e: J6 f, W$ E2. ndarray.resize(new_shape[, refcheck]) Change shape and size of array in-place. 示例代码如下:+ J' j6 G; h% O) s+ D5 b
! ~ C9 ~: M( [; `7 B0 x9 Q# t# ^3. 修改类型 ndarray.astype(type) 示例代码如下:) B' c1 C8 v( a1 x" B
3 N/ ^( e- k$ _8 W8 z9 F3 r8 p
4. 修改小数位数 ndarray.round(arr, out) Return a with each element rounded to the given number of decimals. 示例代码如下: ; ]$ f. |% U% y1 r# j8 |" i1 k) |2 J3 r* o
5. ndarray.flatten([order]) Return a copy of the array collapsed into one dimension. 示例代码如下: 3 Z8 r% `5 Y3 I3 J/ ] ) l* v6 {# D4 q( G6. ndarray.T 数组的转置 将数组的行、列进行互换 示例代码如下:' W+ |; ~+ G- B- u$ N3 W
7 P3 c: C4 z7 V
7. ndarray.tostring([order])或者ndarray.tobytes([order]) Construct Python bytes containing the raw data bytes in the array. 转换成bytes5 r" R6 P' w2 }: d
4 F- d' I- g0 w5 O8. ndarray.copy([order]) Return a copy of the array. 当我们不想修改某个数据的时候,就可以去进行拷贝操作。在拷贝的数据上进行操作,示例代码如下:6 Q- ^! ~" f4 I( w; Q1 X6 _7 G5 e& V
) ~: c! k3 |% E% a3 V/ O& K- f0 G8 k* R s1 K3 Z
4. 数组运算 7 M! \+ U `/ w0 W' ?* ], }1 S) {) `! h: _! |
4.1 逻辑运算4 z/ K4 n H" Q* V e
" R/ U7 A; y" C, H* c
$ P) {% ^, f5 R& S7 i+ }2 qnp.where (三元运算符):通过使用np.where能够进行更加复杂的运算,示例代码如下: 7 \3 f* P! T1 o( Z. R! ?2 c# [/ v W7 r0 q. `; V r5 h
% h% J0 U$ q b6 e- b5 H4.2 统计运算 * R0 l; \# ]1 B9 O& f: g7 U- o6 g, f a6 L( ^. c2 H& O: Z
在数据挖掘/机器学习领域,统计指标的值也是我们分析问题的一种方式。注意:进行统计的时候,axis轴 的取值并不一定, NumPy中不同的API轴的值都不一样,在这里,axis 0代表列, axis 1代表行 去进行统计。常用的指标如下: g+ x: \* `+ V& M$ A
+ S) d3 }2 {5 G; [
min(a[, axis, out, keepdims]) Return the minimum of an array or minimum along an axis. 示例代码如下: " z( N+ a9 ~2 `+ ^2 f* r8 z9 `" ?( d: u8 X! n
max(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis. 示例代码如下:8 B& }) ` H2 }6 t6 C/ S* h2 V
" w- H9 R5 B" @: w
median(a[, axis, out, overwrite_input, keepdims]) Compute the median along the specified axis. 示例代码如下: ( ^0 b0 H$ ~. s: D : y y+ U \. {+ R7 u, c& e Nmean(a[, axis, dtype, out, keepdims]) Compute the arithmetic mean along the specified axis. 示例代码如下:, U7 Y0 N8 v. M ?: t, A+ T
6 M& J0 s( k7 d$ L& T* m, Kstd(a[, axis, dtype, out, ddof, keepdims]) Compute the standard deviation along the specified axis. 示例代码如下: * x! c+ L* y7 n8 ?/ z, o; N1 c5 s- K! U , ^! o& ~9 Y# c& K& I/ Hvar(a[, axis, dtype, out, ddof, keepdims]) Compute the variance along the specified axis. 示例代码如下: # Q" }/ @; V$ s5 x, b : F* t4 J/ m& W) A9 O6 \7 Pnp.argmax(temp, axis=) 示例代码如下:- U1 Y# K5 ^; @# w" I; l
' S+ @/ n' v3 l, Q& enp.argmin(temp, axis=) 示例代码如下:$ e! ]+ C3 [( t% E: I# ^, l
5 [8 F: x V1 r4.3 数组间运算5 y, E3 d4 J$ V) G- a) C
( U5 O% y! x5 J3 E, S: j' ~# T+ J
数组与数的运算,示例代码如下:+ ]6 v, a* g' ~( o8 E
0 S6 n3 F- V- \& u$ J0 c
矩阵运算,什么是矩阵?矩阵,英文matrix,和array的区别矩阵必须是2维的,但是array可以是多维的。示例代码如下:, u% j( \9 V* f; v4 G/ }: ]