Hello Ask,
There is currently no way to do this, though the problem has to do
with the Array._fancySelection() method. Basically, to efficiently
read in the data, PyTables, h5py, and HDF5 require that the indexes
be unique. They then sort the indexes to be monotonic and reorder
after reading.
Probably the easiest way right now is to just read in the unique indexes
that you want into numpy and then make an array with repeated indices
from this. This process (since the reordering is already happening) could
probably be incorporated automatically into PyTables. Feel free to open
an issue on github requesting this feature.
Be Well
Anthony
On Mon, Mar 5, 2012 at 11:19 AM, Ask Jakobsen <a...@linet.dk> wrote:
> Hi all,
>
> I would like to know if anybody knows a work around in pytables that will
> allow to regain numpy's behavior with repeated indices. See code below.
>
> import numpy as np
> import tables
>
> N=5
> M=5
>
> A=np.arange(N*M, dtype=float).reshape(N,M)
>
> with tables.openFile("file.h5", "w") as f:
>
> B=f.createCArray(f.root,"B", tables.Float64Atom(), (N,M))
> B[:]=A
>
> print A[0,[0,1,2]]
> print B[0,[0,1,2]]
>
>
> print A[0,[0,1,2,0]]
> print B[0,[0,1,2,0]] # However: IndexError: Selection lists cannot have
> repeated values
>
> $ python repeated_indices.py
> [ 0. 1. 2.]
> [ 0. 1. 2.]
> [ 0. 1. 2. 0.]
> Traceback (most recent call last):
> File "repeated_indices.py", line 19, in <module>
> print B[0,[0,1,2,0]] # However: IndexError: Selection lists cannot have
> repeated values
> File
> "/share/distro/python/2.7.2/lib/python2.7/site-packages/tables/array.py",
> line 692, in __getitem__
> selection, reorder, shape = self._fancySelection(key)
> File
> "/share/distro/python/2.7.2/lib/python2.7/site-packages/tables/array.py",
> line 622, in _fancySelection
> "Selection lists cannot have repeated values")
> IndexError: Selection lists cannot have repeated values
>
> Best regards,
> Ask
>
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Pytables-users mailing list
> Pytables-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pytables-users
>
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users