[SciPy-user] Array selection help

Stéfan van der Walt stefan at sun.ac.za
Wed Feb 11 15:03:33 EST 2009


Hi Jose

2009/2/11 Jose Luis Gomez Dans <josegomez at gmx.net>:
> Well, there can be quite a lot of them (~10000 at least), so it does take a long while. I was just wondering whether some numpy/scipy array Jedi trick might speed it up :)

Since you have integer labels, you can make use of the following trick:

In [54]: means = np.array([0.1, 0.2, 0.3])

In [55]: means[[1,1,0,1,0,0]]
Out[55]: array([ 0.2,  0.2,  0.1,  0.2,  0.1,  0.1])

I implemented a solution using such a "translation table" (see attached).

Regards
Stéfan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: translate_labels.py
Type: application/octet-stream
Size: 1090 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20090211/174febb5/attachment.obj>


More information about the SciPy-User mailing list