怎么取出numpyndarray的第0列
可以使用以下方式取出numpy.ndarray的第0列:
import numpy as np
# 创建一个3x3的numpy.ndarray
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# 取出第0列
col_0 = a[:, 0]
print(col_0) # 输出 [1 4 7]
通过使用:表示取所有行,然后用数字索引表示取第0列。
原文地址: https://www.cveoy.top/t/topic/fRsm 著作权归作者所有。请勿转载和采集!