首页 > 解决方案 > 如何从numpy数组中提取行,其中col1 = a

问题描述

我每年有一个二维温度值数组,其中每年都有一些值。所以数组看起来像这样:

[[1960, a, b, c, d, e, f ...],
 [1960, a1, b1, c1, d1, e1, f1 ...],
 [1960, a2, b2, c2, d2, e2, f2 ...],
 [1961, a, b, c, d, e, f ...],
 [1961, a1, b1, c1, d1, e1, f1 ...],
 [1961, a2, b2, c2, d2, e2, f2 ...],
 [1962, a, b, c, d, e, f ...],
 [1962, a1, b1, c1, d1, e1, f1 ...],
 [1962, a2, b2, c2, d2, e2, f2 ...]....]

我需要为第 0 列是 1961 的行提取第 1 列中的所有内容(因此所有 a 值)。

有谁知道我会怎么做?谢谢!

标签: pythonnumpynumpy-ndarraydata-processingnumpy-slicing

解决方案


适用于常规 python 列表的解决方案:

[item[1] for item in array if item[0]==1961]

array你的二维输入数组在哪里。


推荐阅读