简体   繁体   English

numpy recarray最小差异

[英]numpy recarray minimum differences

I have a numpy recarray I want to find record where difference of 1st element and last element of record is maximum. 我有一个numpy recarray我想找到记录的第一个元素和最后一个元素的差异最大的记录。

can someone suggest a way to do this. 有人可以建议一种方法来做到这一点。

Set up: 设定:

import numpy
ra = numpy.recarray((10,), 'int,int,int')

Find the index of the maximum of the difference between first field and last field. 找到第一个字段和最后一个字段之间差异的最大值的索引。

idx = numpy.argmax(ra['f0']-ra['f2'])

Retrieve the record using that index 使用该索引检索记录

print ra[idx]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM