; H' M0 |* t" h" o7 u7 `1. ndarray.reshape(shape[, order]) Returns an array containing the same data with a new shape. 示例代码如下:7 ?8 F+ i* o# F! R# O/ p0 c! [9 k! s- i
9 d+ j9 g- G! o, p# F( }/ z
2. ndarray.resize(new_shape[, refcheck]) Change shape and size of array in-place. 示例代码如下: $ B9 K. @& P2 H: c" S 3 H4 E- L5 V3 y" i: Z/ o3. 修改类型 ndarray.astype(type) 示例代码如下: ; n. Z) g( j6 k9 t m6 G0 O $ \# w% l$ Q* p1 J9 [' k# W4. 修改小数位数 ndarray.round(arr, out) Return a with each element rounded to the given number of decimals. 示例代码如下: ' J% F/ @3 @' O5 F! v+ @2 n( \$ [0 L3 J4 y" w
5. ndarray.flatten([order]) Return a copy of the array collapsed into one dimension. 示例代码如下:: s( Y0 \. ~8 t$ u
2 x# O& \4 r; b& {# d
6. ndarray.T 数组的转置 将数组的行、列进行互换 示例代码如下: $ c1 J2 @% C7 \9 e: s 3 z& g' Y$ S/ ~# y- p7. ndarray.tostring([order])或者ndarray.tobytes([order]) Construct Python bytes containing the raw data bytes in the array. 转换成bytes) s9 u3 c D1 p$ @8 G
5 `& P f/ W; [# S5 h8. ndarray.copy([order]) Return a copy of the array. 当我们不想修改某个数据的时候,就可以去进行拷贝操作。在拷贝的数据上进行操作,示例代码如下:& D# i1 W3 Q, D4 N0 P, y: c; |
4 Z; T( U; Z# M; X* o7 y$ J3 [0 e- h
4. 数组运算: G. U" `0 [. l
, `% q, B/ X1 y3 |0 w" f在数据挖掘/机器学习领域,统计指标的值也是我们分析问题的一种方式。注意:进行统计的时候,axis轴 的取值并不一定, NumPy中不同的API轴的值都不一样,在这里,axis 0代表列, axis 1代表行 去进行统计。常用的指标如下: * y6 k# F5 s4 e/ K% n: [% H- q ! t1 i) b @# ~; Z3 p* Y Smin(a[, axis, out, keepdims]) Return the minimum of an array or minimum along an axis. 示例代码如下: 5 b* X, t6 ^7 q4 y. i; D" K! d& u5 n: T: ?# G$ Q# C! ]& q0 o
max(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis. 示例代码如下: , V8 h% E* I" R4 K- J . u2 P, p( j- {* z# o2 cmedian(a[, axis, out, overwrite_input, keepdims]) Compute the median along the specified axis. 示例代码如下:+ H0 F: I/ U" H1 v$ m
# v6 C! p- {$ Rmean(a[, axis, dtype, out, keepdims]) Compute the arithmetic mean along the specified axis. 示例代码如下: . J7 u/ p- y, W$ T8 b p2 C/ o% H+ l6 `6 j' U |0 z6 y2 z( t
std(a[, axis, dtype, out, ddof, keepdims]) Compute the standard deviation along the specified axis. 示例代码如下: $ @( t# P2 t c5 y* s( u5 R2 y0 l0 D
var(a[, axis, dtype, out, ddof, keepdims]) Compute the variance along the specified axis. 示例代码如下:& [0 M% H* ~ k! ?1 V5 Q, ]5 x' _
* H) K$ p! X: v5 V$ u% n: F2 unp.argmax(temp, axis=) 示例代码如下:( E: \/ J* d" ~3 W
5 g, [' o- r- ] A: L
np.argmin(temp, axis=) 示例代码如下: 1 X4 A& y& V2 Y+ b1 ^3 X/ J. Z" m1 }: C
4.3 数组间运算 5 u/ E; C$ W$ ]! b4 w; h9 d6 G$ z( M. s5 l
数组与数的运算,示例代码如下: 5 d- U+ ]9 L4 Q8 a0 c % N9 P0 v7 N9 Q3 L3 a) S1 p4 _矩阵运算,什么是矩阵?矩阵,英文matrix,和array的区别矩阵必须是2维的,但是array可以是多维的。示例代码如下:1 i& R& t. `8 r9 X
$ p/ b+ _% ?9 A0 n' Q, @
3 f( Y8 B o6 D) _1 s. S- t& o4.4 合并分割 h* N1 S/ ^1 n% j( o1 i b T$ D+ B8 Z! [ m8 |
numpy.concatenate((a1, a2, …), axis=0) 示例代码如下:" _/ ^: [" E t, e4 [4 v
, A o+ ?( r4 j- M* T/ p
numpy.hstack(tup) Stack arrays in sequence horizontally (column wise). 示例代码如下: T( T, K' J" I
6 n: ~3 l* G- z7 L; l! Q
numpy.vstack(tup) Stack arrays in sequence vertically (row wise). 示例代码如下:; P" N6 M6 e' K% Y$ `2 }3 \: N: e8 c
7 f) d! Y* F/ p, Nnumpy.split(ary, indices_or_sections, axis=0) Split an array into multiple sub-arrays. 示例代码如下:: C( h6 q. \; D9 E3 F1 r# P r
* s+ k9 i& }* @- _1 G2 z2 j2 _
————————————————1 A" v6 W8 _* d
版权声明:本文为CSDN博主「Amo Xiang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。( T& ~) u" N d4 `: d& R$ W
原文链接:https://blog.csdn.net/xw1680/article/details/105931313 ' V5 M; F% X4 p$ E- Z% s+ [! L9 t8 K- B, q% L3 w! w
$ ^# b( `0 e, S' S5 ^