Python:numpy库中的一些函数简介、使用方法之详细攻略
目录
numpy库中的一些函数简介、使用方法
1、np.concatenate()
1.1、函数案例
import numpy as np
a=np.array([1,2,3])
b=np.array([11,22,33])
c=np.array([44,55,66])
d=np.concatenate((a,b,c),axis=0) # 默认情况下,axis=0可以不写
print(d) #输出array([ 1, 2, 3, 11, 22, 33, 44, 55, 66]),对于一维数组拼接,axis的值不影响最后的结果
1.2、函数用法
concatenate Found at: numpy.core.multiarray concatenate((a1, a2, ...), axis=0, out=None) Join a sequence of arrays along an existing axis. Parameters ---------- a1, a2, ... : sequence of array_like. The arrays must have the same shape, except in the dimension corresponding to `axis` (the first, by default). axis : int, optional. The axis along which the arrays will be joined. Default is 0. out : ndarray, optional. If provided, the destination to place the result. The shape must be correct, matching that of what concatenate would have returned if no out argument were specified. Returns ------- res : ndarray The concatenated array. |
在:numpy.core.multiarray找到连接
|
See Also -------- ma.concatenate : Concatenate function that preserves input masks. array_split : Split an array into multiple sub-arrays of equal or near-equal size. split : Split array into a list of multiple sub-arrays of equal size. hsplit : Split array into multiple sub-arrays horizontally (column wise) vsplit : Split array into multiple sub-arrays vertically (row wise) dsplit : Split array into multiple sub-arrays along the 3rd axis (depth). stack : Stack a sequence of arrays along a new axis. hstack : Stack arrays in sequence horizontally (column wise) vstack : Stack arrays in sequence vertically (row wise) dstack : Stack arrays in sequence depth wise (along third dimension) Notes ----- When one or more of the arrays to be concatenated is a MaskedArray, this function will return a MaskedArray object instead of an ndarray, but the input masks are *not* preserved. In cases where a MaskedArray is expected as input, use the ma.concatenate function from the masked array module instead. |
另请参阅 -------- 马。保存输入掩码的连接函数。 array_split:将一个数组分割成多个相等或的子数组 与大小。 分割:将数组分割成相同大小的多个子数组。 hsplit:水平(按列)将数组分割为多个子数组 垂直(按行)将数组分割为多个子数组 dsplit:沿着第三轴(深度)将数组分割成多个子数组。 堆栈:将数组序列沿着一个新的轴进行堆栈。 hstack:水平排列(按列排列) 垂直(行向)按顺序堆叠数组。 dstack:按深度顺序排列的堆栈数组(沿三维方向) 笔记 ----- 当一个或多个要连接的数组是一个MaskedArray时,这个函数将返回一个MaskedArray对象而不是ndarray,但是输入掩码*不*保留。在需要MaskedArray作为输入的情况下,使用ma。连接函数从掩码数组模块代替。 |
Examples This function will not preserve masking of MaskedArray |
来源:oschina
链接:https://my.oschina.net/u/4330568/blog/4375198