numpy.delete刪除一列或多列的方法
更新時間:2018年04月03日 09:04:50 作者:_JoJo
下面小編就為大家分享一篇numpy.delete刪除一列或多列的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
基礎介紹:
numpy.delete numpy.delete(arr, obj, axis=None)[source] Return a new array with sub-arrays along an axis deleted. For a one dimensional array, this returns those entries not returned by arr[obj]. Parameters: arr : array_like Input array. obj : slice, int or array of ints Indicate which sub-arrays to remove. axis : int, optional The axis along which to delete the subarray defined by obj. If axis is None, obj is applied to the flattened array. Returns: out : ndarray A copy of arr with the elements specified by obj removed. Note that delete does not occur in-place. If axis is None, out is a flattened array.
示例:
1.刪除一列
>>> dataset=[[1,2,3],[2,3,4],[4,5,6]] >>> import numpy as np >>> dataset = np.delete(dataset, -1, axis=1) >>> dataset array([[1, 2], [2, 3], [4, 5]])
2.刪除多列
arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) np.delete(arr, [1,2], axis=1) array([[ 1, 4], [ 5, 8], [ 9, 12]])
以上這篇numpy.delete刪除一列或多列的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Python函數(shù)isalnum用法示例小結(jié)
isalnum()函數(shù)是Python中的一個內(nèi)置函數(shù),用于判斷字符串是否只由數(shù)字和字母組成,其內(nèi)部實現(xiàn)原理比較簡單,只需遍歷字符串中的每一個字符即可,這篇文章主要介紹了Python函數(shù)isalnum用法介紹,需要的朋友可以參考下2024-01-01Python使用itertools模塊實現(xiàn)排列組合功能示例
這篇文章主要介紹了Python使用itertools模塊實現(xiàn)排列組合功能,涉及Python基于itertools模塊product、permutations與combinations_with_replacement方法進行排列、組合等相關操作實現(xiàn)技巧,需要的朋友可以參考下2018-07-07Python+Selenium使用Page Object實現(xiàn)頁面自動化測試
這篇文章主要介紹了Python+Selenium使用Page Object實現(xiàn)頁面自動化測試,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07深入解析神經(jīng)網(wǎng)絡從原理到實現(xiàn)
這篇文章主要介紹了深入解析神經(jīng)網(wǎng)絡從原理到實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07Python如何讀寫二進制數(shù)組數(shù)據(jù)
這篇文章主要介紹了Python如何讀寫二進制數(shù)組數(shù)據(jù),文中講解非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以了解下2020-08-08peewee創(chuàng)建連接前的前置操作wireshark抓包實現(xiàn)
這篇文章主要為大家介紹了peewee創(chuàng)建連接前的前置操作wireshark?抓包實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10