[( J5 h$ p& O1 [7 F0 U* m1 d通过索引切片等获取数组中的值,一维数组示例代码如下:1 ^5 p3 t' h( U
3 r4 w0 X9 O" f, W' ?7 X Z
二维数组示例代码如下:5 b1 o. `( g8 G: S0 J
5 O4 F4 w9 u+ s1 U% Q
三维数组示例代码如下:2 Y0 u j, p# B; i: |8 J
( W; i* V! W0 o8 ~% |+ c
- F3 ?0 I2 y! \* M
4. 数组形状与类型变化% }( ]$ [9 L$ H0 p
& o8 a3 h* ^5 x6 h$ R1. ndarray.reshape(shape[, order]) Returns an array containing the same data with a new shape. 示例代码如下: % X5 O: e, L+ d# z$ @* Z6 J : A$ u2 d/ M; V8 M2. ndarray.resize(new_shape[, refcheck]) Change shape and size of array in-place. 示例代码如下: - u; x& c/ m5 M1 @8 f8 r) E& T+ s% ^6 L3 x: q5 w2 R4 H
3. 修改类型 ndarray.astype(type) 示例代码如下:$ f3 x* [1 j) i. B) U; G
& |( _; ]# U d% ]7 }4. 修改小数位数 ndarray.round(arr, out) Return a with each element rounded to the given number of decimals. 示例代码如下:* ]6 k. K6 r. g7 ~7 Y7 S- d4 k: Q* V
$ ]0 n; l1 Z/ a4 n5. ndarray.flatten([order]) Return a copy of the array collapsed into one dimension. 示例代码如下:3 z. F5 h# m0 s8 y8 G+ e! g& p- |
/ d/ O! F/ _0 @* ^# K. R. a5 {1 K
6. ndarray.T 数组的转置 将数组的行、列进行互换 示例代码如下: & u# y: p7 O; w# A [$ }9 D8 o7 P; C( N
7. ndarray.tostring([order])或者ndarray.tobytes([order]) Construct Python bytes containing the raw data bytes in the array. 转换成bytes 3 S: B0 ^) J M" `+ W! X1 C; t2 `5 B: t
8. ndarray.copy([order]) Return a copy of the array. 当我们不想修改某个数据的时候,就可以去进行拷贝操作。在拷贝的数据上进行操作,示例代码如下: # I% h# d6 f3 Z8 e% G/ c# b8 c" g/ B4 U0 O$ J* I U
/ W7 f" ^* [9 d0 |- n/ @1 F7 E7 I
4. 数组运算 / K' F+ O* Y8 O0 _$ }- W4 o5 M- q& d6 ]/ d1 r q7 X' L
4.1 逻辑运算! p) q; @! }4 b' S- d- P) Y& H
: ?7 ?" N' _! ^' D' N. }% S4.2 统计运算: n" Q. L+ N9 ^3 h3 w2 x
4 `" v9 B: J. R7 }& g8 W
在数据挖掘/机器学习领域,统计指标的值也是我们分析问题的一种方式。注意:进行统计的时候,axis轴 的取值并不一定, NumPy中不同的API轴的值都不一样,在这里,axis 0代表列, axis 1代表行 去进行统计。常用的指标如下:/ y6 b% }: S* g8 x, p6 {
2 G" k& V+ r, Z4 j& Y1 n
min(a[, axis, out, keepdims]) Return the minimum of an array or minimum along an axis. 示例代码如下: 3 y L+ q' u: z' y4 U# G4 n/ l) l. j- z
max(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis. 示例代码如下:* a: K* }& K S) \, x
7 v% t: S& _4 n1 J$ G: h" [
median(a[, axis, out, overwrite_input, keepdims]) Compute the median along the specified axis. 示例代码如下:* W" `9 [$ C% I& Q5 X( @! s B
/ \1 f# z3 d: N7 c. X
mean(a[, axis, dtype, out, keepdims]) Compute the arithmetic mean along the specified axis. 示例代码如下: " }. e8 W7 x# e0 G# S8 M! k: T3 V, Z" I% N+ L
std(a[, axis, dtype, out, ddof, keepdims]) Compute the standard deviation along the specified axis. 示例代码如下: + s# p" \# X) ^' V 5 N, X* v2 {! Svar(a[, axis, dtype, out, ddof, keepdims]) Compute the variance along the specified axis. 示例代码如下: : { S- ]2 }: a0 b 5 H" i1 N( Y: v3 d; Lnp.argmax(temp, axis=) 示例代码如下:5 [. N5 l$ l1 ]* U' z
, F: z8 ]- S# [! ~2 _2 M
np.argmin(temp, axis=) 示例代码如下: 7 y ?$ T& B8 |7 g $ m9 o8 p% t) [7 l8 D( r b/ Y4.3 数组间运算" W6 ~5 ^, G: _7 H: H |2 E4 d
, W6 i+ m! {7 z5 l' z) F# t
数组与数的运算,示例代码如下:) i4 ~7 A, T# k& E" H
, _/ b) Z5 u& l! q: M
矩阵运算,什么是矩阵?矩阵,英文matrix,和array的区别矩阵必须是2维的,但是array可以是多维的。示例代码如下:4 H! T3 [% @) y3 g7 i
: K& U+ ~( {" g7 j% k+ H# z
0 @, `1 q+ k$ c0 f2 O5 W) O4.4 合并分割- G( f! m E$ `# P2 Y
- x. ~5 I" }. d8 W Q9 vnumpy.concatenate((a1, a2, …), axis=0) 示例代码如下: ' U( U0 H0 `7 {* X2 m4 _ " j( a, D ?) T- M3 t* u, `numpy.hstack(tup) Stack arrays in sequence horizontally (column wise). 示例代码如下: ) X" J7 t) q& H: s9 X5 ?% B3 S2 Z) ? }# S; C; R
numpy.vstack(tup) Stack arrays in sequence vertically (row wise). 示例代码如下: 0 @4 v5 r8 I U9 M9 L8 n V# J+ F, t; H7 T, Pnumpy.split(ary, indices_or_sections, axis=0) Split an array into multiple sub-arrays. 示例代码如下:' V( K- Y: r2 Y: ^
/ t* y; Z8 }( `' B. X% S. W———————————————— " A9 \3 W; t' H# s! P! ?+ g版权声明:本文为CSDN博主「Amo Xiang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。& j, c3 ^% C' K" P& z- n
原文链接:https://blog.csdn.net/xw1680/article/details/1059313139 v/ C+ I/ f: ` ~ r! c