1. 程式人生 > >Python陣列提取某一列元素

Python陣列提取某一列元素

Python陣列如何提取某一列元素?

環境:Python3.5

不加工

group=[[1,2],[2,3],[3,4]]
#提取第一列元素
print(group[:,1])
#Out:TypeError: list indices must be integers or slices, not tuple

Numpy轉化

import numpy as np
group=[[1,2],[2,3],[3,4]]
#numpy轉化
ar=np.array(group)
print(ar[:,1])
#Out:[2 3 4]

總結

如果您看到這篇文章有收穫或者有不同的意見,歡迎點贊或者評論。
python
:190341254 丁。