📜  numpy.hsplit()函数| Python

📅  最后修改于: 2022-05-13 01:55:25.404000             🧑  作者: Mango

numpy.hsplit()函数| Python

numpy.hsplit()函数将一个数组水平拆分为多个子数组(按列)。 hsplit 等效于轴=1 的拆分,无论数组维度如何,数组始终沿第二个轴拆分。

代码#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.]]])]