# {- J% [! [- d8 k. c8 [9 ]9 U: J
4. 数组形状与类型变化 , }- ]" H6 a( b1 K: k* ?+ D! a4 S& U2 R9 g
1. ndarray.reshape(shape[, order]) Returns an array containing the same data with a new shape. 示例代码如下: ) I9 ?5 S: s0 E0 u$ K# s3 E3 y1 Q! y" \2 d$ y. K/ x
2. ndarray.resize(new_shape[, refcheck]) Change shape and size of array in-place. 示例代码如下: 1 E) a2 `8 i. E6 s4 Q* C% ~# _" E+ c1 T- ^' }2 {6 w7 X
3. 修改类型 ndarray.astype(type) 示例代码如下:& _; T3 g) l' |& W+ j
+ G. k% r$ y) x8 a% [) {, [
4. 修改小数位数 ndarray.round(arr, out) Return a with each element rounded to the given number of decimals. 示例代码如下:5 B1 x& h4 Y7 U9 N3 E
) T6 \' ^7 z* K5 a) [3 N2 f5 t6 ]
5. ndarray.flatten([order]) Return a copy of the array collapsed into one dimension. 示例代码如下: + R+ n# h$ g: Y ) x' J3 U# K) \, P; w6. ndarray.T 数组的转置 将数组的行、列进行互换 示例代码如下: ' b7 q5 Z& T# t6 L ( s3 h5 s% V. R1 D7. ndarray.tostring([order])或者ndarray.tobytes([order]) Construct Python bytes containing the raw data bytes in the array. 转换成bytes# n' Z, S" T/ j$ @! r6 n
: a5 p5 l$ b. f0 x( o( U- ~/ ?
8. ndarray.copy([order]) Return a copy of the array. 当我们不想修改某个数据的时候,就可以去进行拷贝操作。在拷贝的数据上进行操作,示例代码如下:, ^# E! ?! k$ H% z! R( q& B: m
3 v- J8 w1 w% i: x, u$ f8 I+ q2 Y # B4 Z' x3 X( Q/ _8 U/ K8 B4. 数组运算 7 @1 B8 Z, H8 j, q% F: l+ q) P: T & `9 `% g4 d. ^4 I' h" ]4.1 逻辑运算 8 L6 g4 v% ~7 p' _! [ ' i: p. U7 a! x' y- r 4 V* @2 ^. f8 J5 U通用判断函数,np.all(),示例代码如下:6 B; U% ?7 Y5 ` y
0 S1 |6 A5 T v8 f) w; P8 D* p
np.unique():返回新的数组的数值,不存在重复的值,示例代码如下: ! g% X- N2 }2 H 7 h/ N0 C. k4 G* B/ V( U) r. Unp.where (三元运算符):通过使用np.where能够进行更加复杂的运算,示例代码如下:! b8 @& k# o/ m0 p9 l: g% {
, x" u* i- y: O L
6 r/ ?5 _6 g7 v+ ?min(a[, axis, out, keepdims]) Return the minimum of an array or minimum along an axis. 示例代码如下:: k! h5 b" d* I1 V. Y8 G: R! F1 M& E
' l* V, c. o9 `1 }6 G
max(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis. 示例代码如下: ; f! o6 j( k% n0 t2 P/ z 9 c5 ]* y8 P$ ^9 w7 Hmedian(a[, axis, out, overwrite_input, keepdims]) Compute the median along the specified axis. 示例代码如下: * o5 [# t6 t2 e4 I# {! R1 y' |1 O( U1 K' K$ Q$ U$ a# x
mean(a[, axis, dtype, out, keepdims]) Compute the arithmetic mean along the specified axis. 示例代码如下: + N$ A' X$ [ y: E, H9 i % M6 s2 S" l+ N0 fstd(a[, axis, dtype, out, ddof, keepdims]) Compute the standard deviation along the specified axis. 示例代码如下: ) z" X* F, l5 @- X+ u6 d7 y' w" i2 k; L& o- u5 V \1 W
var(a[, axis, dtype, out, ddof, keepdims]) Compute the variance along the specified axis. 示例代码如下:7 z( W' z, t3 ]8 p+ }" W
* V+ d% I; Q" i5 I: u9 ^3 M
np.argmax(temp, axis=) 示例代码如下: / y; P; b. M: J$ s2 o . p* R' `; v7 \4 k" X' `# H m3 @np.argmin(temp, axis=) 示例代码如下: 0 ?6 l" r! p; p/ _7 D+ C; w / _$ S5 @# Q4 T, b3 {4.3 数组间运算& H. x5 H1 `6 M6 N) n: p, Y