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刪除一列或多列的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python數(shù)據(jù)清洗中的時(shí)間格式化實(shí)現(xiàn)
本文主要介紹了python數(shù)據(jù)清洗中的時(shí)間格式化實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
Python使用matplotlib繪制動(dòng)畫的方法
這篇文章主要介紹了Python使用matplotlib繪制動(dòng)畫的方法,涉及matplotlib模塊的常見使用技巧,需要的朋友可以參考下2015-05-05
解決Python命令行下退格,刪除,方向鍵亂碼(親測(cè)有效)
今天小編就為大家分享一篇解決Python命令行下退格,刪除,方向鍵亂碼(親測(cè)有效),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-01-01
一文搞懂Python中的進(jìn)程,線程和協(xié)程
并發(fā)編程是實(shí)現(xiàn)多任務(wù)協(xié)同處理,改善系統(tǒng)性能的方式。Python中實(shí)現(xiàn)并發(fā)編程主要依靠進(jìn)程、線程和協(xié)程,本文將通過(guò)示例詳解三者的區(qū)別,感興趣的可以了解一下2022-05-05
使用matplotlib庫(kù)實(shí)現(xiàn)圖形局部數(shù)據(jù)放大顯示的實(shí)踐
本文主要介紹了使用matplotlib庫(kù)實(shí)現(xiàn)圖形局部數(shù)據(jù)放大顯示的實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
Python自動(dòng)化之?dāng)?shù)據(jù)驅(qū)動(dòng)讓你的腳本簡(jiǎn)潔10倍【推薦】
數(shù)據(jù)驅(qū)動(dòng)是一種思想,讓數(shù)據(jù)和代碼進(jìn)行分離。這篇文章主要介紹了Python自動(dòng)化之?dāng)?shù)據(jù)驅(qū)動(dòng),讓你的腳本簡(jiǎn)潔10倍,需要的朋友可以參考下2019-06-06

