python - 如何从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 值)。
有谁知道我会怎么做?谢谢!
解决方案
适用于常规 python 列表的解决方案:
[item[1] for item in array if item[0]==1961]
array
你的二维输入数组在哪里。
推荐阅读
- python - 训练自定义对象检测时,平均精度等于 -1
- java - 如何获取存储在数组列表的数组列表中的对象的属性?
- typescript - NSwag:关于如何在 NSwag 工作室中使用类扩展的清晰步骤和干净示例
- javascript - 如何解决 js/jquery 文件之间的冲突?
- python - 为什么我的 Python 回文函数失败了?
- wordpress - Woocommerce - 如果数量发生变化,则显示不同的添加到购物车按钮
- arrays - 从文件创建对象并将它们存储到数组列表中。文件就像 (tools = 2000; fixTools=500 等)
- logging - 监控多个日志文件的最佳方式
- php - 在不同的数据集之间显示空白的 html 表格行
- amazon-web-services - 不了解 AWS Amplify 身份验证刷新令牌方法