numpy.hsplit()函数将一个数组水平(按列)拆分为多个子数组。 hsplit等效于使用axis = 1进行拆分,无论数组尺寸如何,数组始终沿第二条轴拆分。
用法: numpy.hsplit(arr, indices_or_sections)
参数:
arr :[ndarray] Array to be divided into sub-arrays.
indices_or_sections :[int or 1-D array] If indices_or_sections is an integer, N, the array will be divided into N equal arrays along axis.
If indices_or_sections is a 1-D array of sorted integers, the entries indicate where along axis the array is split
Return :[ndarray] A list of sub-arrays.
代码1:
# Python program explaining
# numpy.hsplit() function
# importing numpy as geek
import numpy as geek
arr = geek.arange(16.0).reshape(4, 4)
gfg = geek.hsplit(arr, 2)
print (gfg)
输出:
[array([[ 0., 1.], [ 4., 5.], [ 8., 9.], [ 12., 13.]]), array([[ 2., 3.], [ 6., 7.], [ 10., 11.], [ 14., 15.]])]
代码2:
# Python program explaining
# numpy.hsplit() function
# importing numpy as geek
import numpy as geek
arr = geek.arange(27.0).reshape(3, 3, 3)
gfg = geek.hsplit(arr, 1)
print (gfg)
输出:
[array([[[ 0., 1., 2.], [ 3., 4., 5.], [ 6., 7., 8.]], [[ 9., 10., 11.], [ 12., 13., 14.], [ 15., 16., 17.]], [[ 18., 19., 20.], [ 21., 22., 23.], [ 24., 25., 26.]]])]
相关用法
- Python Wand function()用法及代码示例
- Python sum()用法及代码示例
- Python now()用法及代码示例
- Python id()用法及代码示例
- Python tell()用法及代码示例
- Python int()用法及代码示例
- Python oct()用法及代码示例
- Python hex()用法及代码示例
- Python ord()用法及代码示例
- Python str()用法及代码示例
- Python cmp()用法及代码示例
- Python dir()用法及代码示例
- Python map()用法及代码示例
- Python round()用法及代码示例
- Python cmath.cos()用法及代码示例
- Python seek()用法及代码示例
注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 numpy.hsplit() function | Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。