aa=np.array([1,1,1,np.nan,np.nan,1,1,np.nan])
idx, feq= get_frequency_of_events(aa)
< /code>
Liste der Indizes @ Zu Beginn jeder Gruppe [0, 5] < /p>
Frequenz jeder Gruppe [3, 2] < /p>
ist diese Funktion jedoch langsam, insbesondere bei der Iterierung von 3D -Daten. Wie kann ich eine solche Funktion vectorisieren, um eine schnellere Verarbeitung zu erreichen? < /P>
Hier ist die Funktion < /p>
def get_frequency_of_events(mydata):
"""
Author : Shaaban
Date : Jan 22, 2025
Purpose : get the frequency of repeated consecutive numbers and their indices, this is important when finding the frequency of heatwaves and etc ... All we have to do is to build matrix of ones (or any other number), and NAN. One refers to the existence of the EVENT, and nan refers to the inexistence of the event. Then this function could give you a summary of the the frequency of the events and their associated indices.
tests :
aa=np.array([1,1,0,0,0,1,0,1,1,1,1,0,1,1])
get_frequency(aa)
aa=np.array([1,2,2,3,3,3,4,4,4,4,5,5,5,5,5])
get_frequency(aa)
aa=np.array([1,1,1,1,0,0,1,1,1])
get_frequency(aa)
aa=np.arange(10)
get_frequency(aa)
aa=np.ones(10)
get_frequency(aa)
# CAUTION CAUTION CAUTION
#For heatwave numbers, etc , make your array consits of fixed number (any number) that is associated with an evens and Nan for days/hours/month not associated with events. The trick here is that no nan could ever be equal to another nan.
aa=np.array([1,1,1,np.nan,np.nan,1,1,np.nan])
idx, feq= get_frequency(aa)
"""
index_list=[]
events_frequency_list=[]
idx_last_num=len(mydata)-1
counter=0
ii=0
while(ii
All, Die folgende Funktion get_frequency_of_events < /code> erkennt die Häufigkeit aufeinanderfolgender Zahlen, z. B. < /p> [code]import numpy as np aa=np.array([1,2,2,3,3,3,4,4,4,4,5,5,5,5,5]) get_frequency_of_events(aa) [/code] this yields the following: list of indices @ the beginning of each group [1, 3, 6, 10] frequency of each group [2, 3, 4, 5] another example, [code]aa=np.array([1,1,1,np.nan,np.nan,1,1,np.nan]) idx, feq= get_frequency_of_events(aa) < /code> Liste der Indizes @ Zu Beginn jeder Gruppe [0, 5] < /p> Frequenz jeder Gruppe [3, 2] < /p> ist diese Funktion jedoch langsam, insbesondere bei der Iterierung von 3D -Daten. Wie kann ich eine solche Funktion vectorisieren, um eine schnellere Verarbeitung zu erreichen? < /P> Hier ist die Funktion < /p> def get_frequency_of_events(mydata): """ Author : Shaaban Date : Jan 22, 2025 Purpose : get the frequency of repeated consecutive numbers and their indices, this is important when finding the frequency of heatwaves and etc ... All we have to do is to build matrix of ones (or any other number), and NAN. One refers to the existence of the EVENT, and nan refers to the inexistence of the event. Then this function could give you a summary of the the frequency of the events and their associated indices. tests :
# CAUTION CAUTION CAUTION #For heatwave numbers, etc , make your array consits of fixed number (any number) that is associated with an evens and Nan for days/hours/month not associated with events. The trick here is that no nan could ever be equal to another nan.
Dies ist ein sehr erfundenes Beispiel, um das Problem zu destillieren, das ich beobachte. Ich weiß, dass ich es umgehen kann, aber ich möchte immer noch verstehen, warum das nicht so funktioniert,...
Dies ist eine knifflige Situation. Ich versuche, einen SVG-Container zu erstellen, der Maus-Drag-Bewegungen verfolgt. Wenn die Maus abgehalten wird, startet sie einen Prozess, bei dem ein weiterer...
Ich arbeite an einem Windows-Gaming-Frontend, das alle installierten Steam-, Epic- und GOG-Spiele sowie die auf dem Laufwerk C installierten Spiele anzeigt. Wenn ich jedoch ein Spiel mit...