[SciPy-user] Array selection help

Stéfan van der Walt stefan@sun.ac...
Wed Feb 11 14:03:33 CST 2009

Hi Jose

2009/2/11 Jose Luis Gomez Dans <josegomez@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).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: translate_labels.py
Type: application/octet-stream
Size: 1089 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-user/attachments/20090211/174febb5/attachment.obj 

More information about the SciPy-user mailing list