numpy.delete刪除一列或多列的方法
更新時間:2018年04月03日 09:04:50 作者:_JoJo
下面小編就為大家分享一篇numpy.delete刪除一列或多列的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
基礎(chǔ)介紹:
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)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python數(shù)據(jù)清洗中的時間格式化實現(xiàn)
本文主要介紹了python數(shù)據(jù)清洗中的時間格式化實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
一文搞懂Python中的進(jìn)程,線程和協(xié)程
并發(fā)編程是實現(xiàn)多任務(wù)協(xié)同處理,改善系統(tǒng)性能的方式。Python中實現(xiàn)并發(fā)編程主要依靠進(jìn)程、線程和協(xié)程,本文將通過示例詳解三者的區(qū)別,感興趣的可以了解一下2022-05-05
使用matplotlib庫實現(xiàn)圖形局部數(shù)據(jù)放大顯示的實踐
本文主要介紹了使用matplotlib庫實現(xiàn)圖形局部數(shù)據(jù)放大顯示的實踐,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02
Python自動化之?dāng)?shù)據(jù)驅(qū)動讓你的腳本簡潔10倍【推薦】
數(shù)據(jù)驅(qū)動是一種思想,讓數(shù)據(jù)和代碼進(jìn)行分離。這篇文章主要介紹了Python自動化之?dāng)?shù)據(jù)驅(qū)動,讓你的腳本簡潔10倍,需要的朋友可以參考下2019-06-06

