" m9 e U+ J: E$ b. {; J; ` , Y2 S3 u, c* n% B$ Y+ d3 r4. 数组形状与类型变化 y3 h" l2 W- y! C5 X2 Q* h, L2 h ~5 X
1. ndarray.reshape(shape[, order]) Returns an array containing the same data with a new shape. 示例代码如下: L$ I8 ]# H# Z3 | - O2 F. a4 {7 s( B4 K2. ndarray.resize(new_shape[, refcheck]) Change shape and size of array in-place. 示例代码如下:- |- ~: N+ l2 A; j. U9 u4 d3 b
3 ^: O$ g- h1 j+ M, w
3. 修改类型 ndarray.astype(type) 示例代码如下: & ?9 h3 A+ _0 Y9 i- S# S) X3 U) V" c Y; n# A6 Z# ]0 r# ?; P; K( _
4. 修改小数位数 ndarray.round(arr, out) Return a with each element rounded to the given number of decimals. 示例代码如下:3 L W, N% I( d( W. J4 N* h
5 X" v2 d0 _5 w* p0 V# ~8 o5. ndarray.flatten([order]) Return a copy of the array collapsed into one dimension. 示例代码如下:- G6 e" ^$ C q* k( T
, \/ k2 Y. m, R6 q* ~" c. |
6. ndarray.T 数组的转置 将数组的行、列进行互换 示例代码如下:6 r$ o$ S. W' c2 G7 j* y
/ V7 W# n# _4 W' m7. ndarray.tostring([order])或者ndarray.tobytes([order]) Construct Python bytes containing the raw data bytes in the array. 转换成bytes / F' j/ ~' I7 Q2 I3 l$ @0 T& b) r- q3 h( W Q
8. ndarray.copy([order]) Return a copy of the array. 当我们不想修改某个数据的时候,就可以去进行拷贝操作。在拷贝的数据上进行操作,示例代码如下: 9 B/ b' U; r2 _' E H" I0 h 1 q3 q: I. a! X& `/ r' a, F& V , g* T' A- X6 D$ V+ f4 [6 q4. 数组运算6 ]6 |( @8 e4 k. G' S6 E' Q4 P4 v
6 v1 c7 a" J5 O, V B. f' Q; kmin(a[, axis, out, keepdims]) Return the minimum of an array or minimum along an axis. 示例代码如下:7 w5 [! J: J _" m- j7 [1 h
. r+ P; J. Z1 ]! I% G2 p
max(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis. 示例代码如下: 0 g. S0 d" t; h# r q+ I$ ~: y% i. U! q; U9 a- e: n4 t
median(a[, axis, out, overwrite_input, keepdims]) Compute the median along the specified axis. 示例代码如下:6 S0 v! c9 o1 Y2 g
4 l' Q$ {2 [. e& @( V
mean(a[, axis, dtype, out, keepdims]) Compute the arithmetic mean along the specified axis. 示例代码如下: ( I- n o6 Z! c! A& V2 F5 `2 \ / R, r- H! b& M- {std(a[, axis, dtype, out, ddof, keepdims]) Compute the standard deviation along the specified axis. 示例代码如下: 5 {. j5 G o% [2 \ H1 Y6 `- I! {9 c7 a5 v
var(a[, axis, dtype, out, ddof, keepdims]) Compute the variance along the specified axis. 示例代码如下:0 R6 V" E( h* `& V, t4 h8 S2 r
8 J2 \/ | o/ f' e- \np.argmax(temp, axis=) 示例代码如下: 9 o) y6 {1 S3 K& w6 t5 c, x3 X4 M$ n: u
np.argmin(temp, axis=) 示例代码如下:9 `; j( h. Q" Q: b4 @! r E$ R8 n' @9 v
+ L4 y- ~. r( d6 W5 d; B
4.3 数组间运算8 e- C( x* ?3 {( h" |
3 f& b$ w/ S$ E i
数组与数的运算,示例代码如下:1 @: s5 z+ M/ j# A# K
0 o; @% e: f& q9 b- U
矩阵运算,什么是矩阵?矩阵,英文matrix,和array的区别矩阵必须是2维的,但是array可以是多维的。示例代码如下: " E; A; c7 Z7 g4 F + C: Q" ?6 n! C+ I5 n) j! ]1 K! \" A
4.4 合并分割; }, l, l7 k* G# m% g
1 n& X& Y; M: I# o8 P6 ~
numpy.concatenate((a1, a2, …), axis=0) 示例代码如下: / E) y- Q9 P& t9 l7 C * o9 l* e) n5 N1 xnumpy.hstack(tup) Stack arrays in sequence horizontally (column wise). 示例代码如下: 6 `2 q s l9 L. T+ A% ]9 z. @ ^* q1 n) |3 o0 Z0 \& B+ ?
numpy.vstack(tup) Stack arrays in sequence vertically (row wise). 示例代码如下: " o8 C) T/ G1 \4 K. t J- q" b7 m* O% y. B) {- u& ynumpy.split(ary, indices_or_sections, axis=0) Split an array into multiple sub-arrays. 示例代码如下: . y6 S6 g7 x6 n j, T) n1 b+ b: [, X E k' d
———————————————— ) W2 e% Q& \( q/ R9 j9 Z3 v3 q版权声明:本文为CSDN博主「Amo Xiang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。5 s: K; S* N& `5 K8 o" `
原文链接:https://blog.csdn.net/xw1680/article/details/105931313( X, K! }2 J+ {3 Q& t s