當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy.vsplit()用法及代碼示例

numpy.vsplit()函數將一個數組垂直(行)拆分為多個子數組。 vsplit等效於使用axis = 0進行拆分(默認),無論數組尺寸如何,數組始終沿第一個軸拆分。

用法: numpy.vsplit(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.vsplit() function 
  
# importing numpy as geek  
import numpy as geek 
  
arr = geek.arange(9.0).reshape(3, 3) 
  
gfg = geek.vsplit(arr, 1) 
  
print (gfg)

輸出:

[array([[ 0.,  1.,  2.],
       [ 3.,  4.,  5.],
       [ 6.,  7.,  8.]])]


代碼2:

# Python program explaining 
# numpy.vsplit() function 
  
# importing numpy as geek  
import numpy as geek 
  
arr = geek.arange(36.0).reshape(6, 6) 
  
gfg = geek.vsplit(arr, 2) 
  
print (gfg)

輸出:

[array([[  0.,   1.,   2.,   3.,   4.,   5.],
       [  6.,   7.,   8.,   9.,  10.,  11.],
       [ 12.,  13.,  14.,  15.,  16.,  17.]]), array([[ 18.,  19.,  20.,  21.,  22.,  23.],
       [ 24.,  25.,  26.,  27.,  28.,  29.],
       [ 30.,  31.,  32.,  33.,  34.,  35.]])]

相關用法


注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.vsplit() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。