: q% z6 ]; ], b3 c Z1 s其中M为平均值,n为数据总个数,s为标准差,s^2可以理解一个整体为方差。& F6 o5 Y# m, J8 e/ ]
3 B2 Y( J. o( W$ s: M
通过索引切片等获取数组中的值,一维数组示例代码如下:; p' t2 `; E' f( B: V7 r6 g
; c0 M$ Z% Q$ r4 j. F5 u2 j6 `/ U1 y# _' A3 T3 r. ^
4. 数组形状与类型变化 ) Q+ m Z" B+ i. q R + [6 r' s7 O \% S$ |2 G2 e$ F1. ndarray.reshape(shape[, order]) Returns an array containing the same data with a new shape. 示例代码如下:% g3 g! N! K/ p( e! _
+ I% x! v, D" x. j, q X1 L& m+ P5 }/ e/ R
2. ndarray.resize(new_shape[, refcheck]) Change shape and size of array in-place. 示例代码如下:$ Y, ~; m* K/ X0 n% m
+ P5 Z! w: i' O) U0 S' T
3. 修改类型 ndarray.astype(type) 示例代码如下:, q4 K3 K7 }& d) a
7 o7 m" N3 D8 n0 Y
4. 修改小数位数 ndarray.round(arr, out) Return a with each element rounded to the given number of decimals. 示例代码如下: ; v3 J) l0 \# b d3 \, w7 M7 H( X6 S5. ndarray.flatten([order]) Return a copy of the array collapsed into one dimension. 示例代码如下:3 a) K6 |9 F6 J- |: z6 B& @
' ?$ J: f% d# C0 ]' T- ~! C! W. n
6. ndarray.T 数组的转置 将数组的行、列进行互换 示例代码如下: " |5 U1 Q3 j( S* J1 r8 i2 r% K1 D/ R7 V% ~
7. ndarray.tostring([order])或者ndarray.tobytes([order]) Construct Python bytes containing the raw data bytes in the array. 转换成bytes / o) [' W" G6 u( S) z% v' r7 D# y* C0 ~/ R; {& }' W# l L
8. ndarray.copy([order]) Return a copy of the array. 当我们不想修改某个数据的时候,就可以去进行拷贝操作。在拷贝的数据上进行操作,示例代码如下: 6 Z% |) {( r7 l: y" F9 d7 Q3 _2 a
: H% t7 @& ~; ~9 l& l: _9 X, \8 Z4. 数组运算 $ L' ]8 d0 Z5 x. Y, M4 Z9 m1 \ F( t5 |8 K" X1 w0 L7 i. j4.1 逻辑运算 ) u# Y; t$ E) U9 F 8 d5 Z. I9 z4 `0 a% A: N; j& S, r5 t, c D( ]# x
通用判断函数,np.all(),示例代码如下: # j8 R2 ?4 y6 c3 A0 W+ V, r$ F. O9 u4 R/ a
np.unique():返回新的数组的数值,不存在重复的值,示例代码如下:1 m K; U3 V- p) b5 Q
, l- I; U/ |4 [2 P+ |- p- S
np.where (三元运算符):通过使用np.where能够进行更加复杂的运算,示例代码如下: ) L J+ m, @; p9 `: D7 @) W ' y! ?$ F6 }! H7 c9 O% j W& J- w9 s. f3 k" P+ A7 @5 ~
4.2 统计运算 & A6 G( H& f1 b: q3 `7 p % V* \* `7 v ~- F9 j5 B在数据挖掘/机器学习领域,统计指标的值也是我们分析问题的一种方式。注意:进行统计的时候,axis轴 的取值并不一定, NumPy中不同的API轴的值都不一样,在这里,axis 0代表列, axis 1代表行 去进行统计。常用的指标如下: 5 v! I2 B8 u; F! k+ Q* c, T/ o7 \- M! s& Q$ b5 U' R* o
min(a[, axis, out, keepdims]) Return the minimum of an array or minimum along an axis. 示例代码如下:; s1 q9 d; v7 O1 d
" x2 s9 q# H1 m8 K3 lmax(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis. 示例代码如下: : C3 h$ [; h( p' ]3 g' G8 I1 e& V0 m: {
median(a[, axis, out, overwrite_input, keepdims]) Compute the median along the specified axis. 示例代码如下:& Y- X; C, |0 B9 P- q9 y7 L3 g
% F$ M- b" b' c, U
mean(a[, axis, dtype, out, keepdims]) Compute the arithmetic mean along the specified axis. 示例代码如下:3 p, ?2 u, c5 z; n( @ I
- |' ?! x3 N# @- Estd(a[, axis, dtype, out, ddof, keepdims]) Compute the standard deviation along the specified axis. 示例代码如下:5 i8 e( Z" N. [2 A7 I
) h7 h% Z& i/ s) \: Lvar(a[, axis, dtype, out, ddof, keepdims]) Compute the variance along the specified axis. 示例代码如下:" w8 l* F# Y0 j f# t- y
3 l. m# T0 |! W& e! L6 \np.argmax(temp, axis=) 示例代码如下: - L+ d( ^% O' T' Z( C5 i% r+ T 4 e8 R8 ^4 D# ]7 jnp.argmin(temp, axis=) 示例代码如下: $ `: R+ q* u+ }: y + T) d) w( {* E& d% S# Q4.3 数组间运算3 h* ^$ m; U" q4 n. Y- i' }: f
+ f% G! [' k. q3 M, _+ L数组与数的运算,示例代码如下:/ O* v; N2 S: o9 C6 ?; S" b
( B2 i' o. W# I# K( r" s矩阵运算,什么是矩阵?矩阵,英文matrix,和array的区别矩阵必须是2维的,但是array可以是多维的。示例代码如下:5 ]2 E' O5 V( z! A8 N2 h
) S& F+ S9 q; y: C" Z
; I$ l5 J: S! V! }2 y7 ^( K. o6 U
4.4 合并分割 & `+ `4 C! R% e4 ] & t T0 {/ N# w2 T2 Xnumpy.concatenate((a1, a2, …), axis=0) 示例代码如下: & {' Q4 h7 ?) N5 n+ o$ J N# ?1 |- c3 d$ O) z4 h3 A: Enumpy.hstack(tup) Stack arrays in sequence horizontally (column wise). 示例代码如下:+ e4 Y+ b) d8 M" z; S5 Y- _' m
5 V6 V8 ~, F& J0 w! b" K7 z) z8 Z
numpy.vstack(tup) Stack arrays in sequence vertically (row wise). 示例代码如下:6 y& J8 Q3 L) u- j! r
: I8 I9 M/ T3 o7 ]
numpy.split(ary, indices_or_sections, axis=0) Split an array into multiple sub-arrays. 示例代码如下: 8 A+ L0 f$ }( G( J3 e/ U. k) i8 ?
————————————————4 A6 C( @& s& Y$ v/ k
版权声明:本文为CSDN博主「Amo Xiang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 ; z; I D# X+ D8 d; n原文链接:https://blog.csdn.net/xw1680/article/details/1059313139 H7 n" f1 \2 }" E9 k