python取某一列_python数组或列表删除或读取某一列

雨歌
2021-09-30 / 0 评论 / 57 阅读 / 正在检测是否收录...

python数组或列表删除或读取某一列

发布时间:2018-05-13 13:00,

浏览次数:1479

, 标签:

python

import numpy as np >>> data=[[1,2,3],[2,3,4],[4,5,6]] >>> data [[1, 2, 3],

[2, 3, 4], [4, 5, 6]] >>> #列表的读取或删除某一列 >>> #1.读取 >>> data1=np.array(data) >>>

data1 array([[1, 2, 3], [2, 3, 4], [4, 5, 6]]) >>> data1[:,0] array([1, 2, 4])

2.删除 >>> np.delete(data1,0,axis=1) array([[2, 3], [3, 4], [5, 6]]) >>>

data1 array([[1, 2, 3], [2, 3, 4], [4, 5, 6]]) >>> #numpy数组的读取或删除某一列 >>>

data=np.array([[1,2,3],[2,3,4],[4,5,6]]) >>> data array([[1, 2, 3], [2, 3, 4],

[4, 5, 6]]) >>> #1.读取 >>> data[:,1] array([2, 3, 5]) >>> #2.删除 >>>

np.delete(data,1,axis=1) array([[1, 3], [2, 4], [4, 6]]) >>> data array([[1, 2,

3], [2, 3, 4], [4, 5, 6]])

1

评论 (0)

取消