What is the fastest way to fetch numpy arrays?

I have a 3D (time, X, Y) numpy array containing 6 hour time series for several years. (say 5). I would like to create a selective time series containing 1 instance of each calendar day, randomly taken from the available entries (5 possibilities per day), as follows.

  • 01/01/2006
  • January 02: 2011
  • January 03: 2009
  • ...

This means that I need to take 4 values ​​from 01/01/2006, 4 values ​​from 02/01/2011, etc. I have a working version that works as follows:

  • Modify the input array to add the year dimension (time, year, X, Y).
  • Create an array of 365 values ​​from randomly generated integers from 0 to 4
  • Use np.repeat and an array of integers to extract only the appropriate values:

Example:

sampledValues = Variable[np.arange(numberOfDays * ValuesPerDays), sampledYears.repeat(ValuesPerDays),:,:]

, , , / ? , , .

?

, , 29- feb .

- 365- , .. , .

+5
2

2008 366 , .

scikits.timeseries:

import scikits.timeseries as ts

start_date = ts.Date('H', '2006-01-01 00:00')
end_date = ts.Date('H', '2010-12-31 18:00')
arr3d = ... # your 3D array [time, X, Y]

dates = ts.date_array(start_date=start_date, end_date=end_date, freq='H')[::6]
t = ts.time_series(arr3d, dates=dates)
# just make sure arr3d.shape[0] == len(dates) !

t //:

t[np.logical_and(t.day == 1, t.month == 1)]

, :

for day_of_year in xrange(1, 366):
    year = np.random.randint(2006, 2011)

    t[np.logical_and(t.day_of_year == day_of_year, t.year == year)]
    # returns a [4, X, Y] array with data from that day

t, .

+3

, .

, ( 0 365) , , n*365 + offset.

, , , , , .

0

All Articles