BIDS / datarray

Prototyping numpy arrays with named axes for data management.
http://bids.github.com/datarray
Other
87 stars 20 forks source link

Support fancy indexing #42

Open fperez opened 13 years ago

fperez commented 13 years ago

Currently fancy indexing isn't supported at all.

In [79]: cap_ax_spec = 'capitals', ['washington', 'london', 'berlin', 'paris', 'moscow']
    ...: time_ax_spec = 'time', ['0015', '0615', '1215', '1815']
    ...: t = DataArray(np.arange(4*5).reshape(4,5), [time_ax_spec, cap_ax_spec])
    ...: t.axis.capitals[['paris', 'london']]
    ...: 
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
/home/fperez/research/code/datarray/datarray/ in ()
      2 time_ax_spec = 'time', ['0015', '0615', '1215', '1815']
      3 t = DataArray(np.arange(4*5).reshape(4,5), [time_ax_spec, cap_ax_spec])
----> 4 t.axis.capitals[['paris', 'london']]

/home/fperez/research/code/datarray/datarray/datarray.py in __getitem__(self, key)
    218         # XXX We don't handle fancy indexing at the moment

    219         if isinstance(key, (np.ndarray, list)):
--> 220             raise NotImplementedError('We do not handle fancy indexing yet')
    221         parent_arr = self.parent_arr # local for speed
    222         parent_arr_ndim = parent_arr.ndim

NotImplementedError: We do not handle fancy indexing yet
fperez commented 13 years ago

As a preliminary plan, we can try to:

fperez commented 13 years ago

An example where you manually pick out elements, for example, will necessarily drop dimensions, and something like this can't really preserve any labels/axes, since the output's geometry has nothing to do with the input:

In [110]: a  = arange(12).reshape(3,4)
     ...: b = a[[(1,2,1),(0,1,3)]]
     ...: print a
     ...: print b
[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]]
[4 9 7]