0

I have a 3D matrix Temp[time,x,y] representing temperatures over a region at different times. I want to count the number of times the temperature is in a given range [t0, t1, t2, ..., tn]. That is, I want to compute the histogram of Temp[time,x,y] as a matrix HISTO such that:

Histo[0,x,y] = the number of times Temp[:,x,y] is in a range t0-t1
Histo[1,x,y] = the number of times Temp[:,x,y] is in a range t1-t2

What I have tried:

  1. looping through each (x,y) and use np.histogram on Temp[:,x,y]
  2. looping through each range and compute np.count_nonzero((Temp>tn) & (Temp<tm), axis=0)

Is there any other way of doing this? can I use hitogram over a given axe? ranges could be equally spaced if necesary.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
SandiaDeDia
  • 291
  • 2
  • 9
  • 2
    "What I have tried..." Please [edit] your question to include code to go along with your verbal descriptions. – Code-Apprentice Apr 01 '21 at 22:33
  • 1
    Is the range equidistant? (Is t1-t0==t2-t1==t3-t2==...?) – DYZ Apr 01 '21 at 23:45
  • 2
    I think this is what you are looking for: https://stackoverflow.com/a/46374159/4975981 – Ehsan Apr 02 '21 at 00:47
  • Thank you @Ehsan, yes I think it is. I have also been working on a solution using a code you posted some time ago as a reply to another question I asked. :-) https://stackoverflow.com/questions/62629682/removing-loops-in-numpy-for-a-simple-matrix-assignment – SandiaDeDia Apr 02 '21 at 01:36
  • @SandiaDeDia does the answers not include what you are looking for? From my understanding, the recommended solution is direct answer (minus the change in the axis you might need to do or simply transpose). Please let us know if it is not directly what you are looking for and we can help better. Thank you – Ehsan Apr 02 '21 at 04:29

0 Answers0