日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

玩转NumPy——split()函数使用详解

發(fā)布時間:2024/9/27 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 玩转NumPy——split()函数使用详解 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

函數(shù)原型:

split(ary, indices_or_sections, axis=0)

參數(shù)說明:

ary:被分割的數(shù)組(A partitioned array)

?indices_or_sections:如果是一個整數(shù),就用該數(shù)平均切分,如果是一個數(shù)組,為沿軸切分的位置(左開右閉)。

If it is an integer, the number is split evenly, if it is an array, the position of the split along the axis (left open and right closed)

?axis:設(shè)置沿著哪個方向進行切分,默認為 0,橫向切分,即水平方向。為 1 時,縱向切分,即豎直方向。

eg:

import numpy as npa = np.arange(9)print ('第一個數(shù)組:') print (a) print ('\n')print ('將數(shù)組分為三個大小相等的子數(shù)組:') b = np.split(a,3) print (b) print ('\n')print ('將數(shù)組在一維數(shù)組中表明的位置分割:') b = np.split(a,[4,7]) print (b)result: 第一個數(shù)組: [0 1 2 3 4 5 6 7 8]將數(shù)組分為三個大小相等的子數(shù)組: [array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8])]將數(shù)組在一維數(shù)組中表明的位置分割: [array([0, 1, 2, 3]), array([4, 5, 6]), array([7, 8])]

eg:

import numpy as npa = np.arange(16).reshape(4, 4) print('第一個數(shù)組:') print(a) print('\n') print('默認分割(0軸):') b = np.split(a,2) print(b) print('\n')print('沿垂直方向分割:') c = np.split(a,2,1) print(c) print('\n')print('沿水平方向分割:') d= np.hsplit(a,2) print(d)result: 第一個數(shù)組: [[ 0 1 2 3][ 4 5 6 7][ 8 9 10 11][12 13 14 15]]默認分割(0軸): [array([[0, 1, 2, 3],[4, 5, 6, 7]]), array([[ 8, 9, 10, 11],[12, 13, 14, 15]])]沿垂直方向分割: [array([[ 0, 1],[ 4, 5],[ 8, 9],[12, 13]]), array([[ 2, 3],[ 6, 7],[10, 11],[14, 15]])]沿水平方向分割: [array([[ 0, 1],[ 4, 5],[ 8, 9],[12, 13]]), array([[ 2, 3],[ 6, 7],[10, 11],[14, 15]])]


建議收藏,方便下次查閱。

總結(jié)

以上是生活随笔為你收集整理的玩转NumPy——split()函数使用详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。