简体   繁体   English

查找numpy ndarray的索引

[英]Finding indices of numpy ndarray

I have a numpy.ndarray (data) that has 5 elements and each element has 2042 rows and two columns. 我有一个有5个元素的numpy.ndarray(数据),每个元素都有2042行和两列。 The first column contains dates (on 15-minute intervals) and the second contains temperatures. 第一列包含日期(以15分钟为间隔),第二列包含温度。 I am working a script that will find the max temperature in a 24-hour period. 我正在编写一个脚本,它将在24小时内找到最高温度。 I have a working script for that. 我有一个工作脚本。

x1=0
y1=95
maxTblue=[] 

for i in range(int(len(data[0])/96)+1):
    #collect the max temp for 24-hr period
    maxTblue.append(max(data[0][x1:y1,1]))
    #add 96 to shift to the next 24-hr period
    x1+=96
    y1+=96

Now, I want to be able to collect the date where the max temperature occurs for each 24-hour period. 现在,我希望能够收集每个24小时内出现最高温度的日期。 I tried the following script but it's giving me the wrong dates. 我尝试了以下脚本,但是给了我错误的日期。 The dates should increase by 24-hour periods, but the current script is returning dates from the first 24-hour period. 日期应增加24小时,但是当前脚本返回的是前24小时的日期。

maxdateBlue=[]
locblue=[]
x3=0
y3=95
for i in range(int(len(data[0])/96)+1):
    #index for the max temp 
    locblue.append(np.where(data[0][x3:y3,1]==maxTblue[i]))
    #date where the max temp occurs
    maxdateBlue.append(data[0][locblue[i],0])
    x3+=96
    y3+=96

How do I properly use np.where, or how do I use another indices command to find out when my max temperatures occur? 如何正确使用np.where或如何使用另一个索引命令找出何时出现最高温度?

要在numpy数组中找到最大值的索引,请使用np.argmax()

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

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