python 3D numpy array time index
<p>Is there a way to index a 3 dimensional array using some form of time index (datetime etc.) on the 3rd dimension?</p>

<p>My problem is that I am doing time series analysis on several thousand radar images and I need to get, for example, monthly averages. However if i simply average over every 31 arrays in the 3rd dimension it becomes inacurate due to shorter months and missing data etc. </p>

<p>you can use pandas module. it supports indexing by date/datetime range. it also support multiindexing, which allows you to work with multidimensional data in 2D manner. </p>

<pre><code>&gt;&gt;&gt; rng = pd.date_range('1/1/2016', periods=100, freq='D')
&gt;&gt;&gt; rng[:5]

DatetimeIndex(['2016-01-01', '2016-01-02', '2016-01-03', '2016-01-04', '2016-01-05'], dtype='datetime64[ns]', freq='D')

&gt;&gt;&gt; ts = pd.Series(np.random.randn(len(rng)), index=rng)
&gt;&gt;&gt; ts.head()

2016-01-01    0.119762
2016-01-02   -0.010990
2016-01-03    0.226537
2016-01-04   -0.087559
2016-01-05    0.484426
Freq: D, dtype: float64

&gt;&gt;&gt; ts.resample('M').mean()

2016-01-31   -0.171578
2016-02-29    0.055878
2016-03-31   -0.243225
2016-04-30   -0.015087
Freq: M, dtype: float64
</code></pre>

<p>check some detailed info below:</p>

<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.html</a>
<a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/timeseries.html</a>
<a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/advanced.html</a></p>

python arrays datetime numpy multidimensional-array