[SciPy-user] indices, lists and arrays
Francesc Altet
faltet at carabos.com
Wed Jun 6 11:34:14 EDT 2007
El dc 06 de 06 del 2007 a les 16:13 +0200, en/na Emanuele Zattin va
escriure:
> i have something like this:
>
> sizes = ndimage.sum(bl_img, labels=bl_l, index=range(1,bl_n+1))
> sizes = array(sizes)
> bl_obj_indices = where(sizes<21)
> bl_l[bl_objects[bl_obj_indices]] = 0
>
> sizes was a list, but i converted it to an array in order to use the
> function where on it
> where returns an array of arrays, something like (array([14, 17]),)
> bl_objects is the output of ndimage.find_objects and is a list. this
> means that the assignment on the last row of the proposed code does
> not work.
> is there an elegant solution to solve the problem?
In order to use fancy indexing, you always need an array as the base,
so, the next should do the trick:
bl_l[array(bl_objects)[bl_obj_indices]] = 0
or, for short:
bl_l[array(bl_objects)[sizes<21]] = 0
HTH,
--
Francesc Altet | Be careful about using the following code --
Carabos Coop. V. | I've only proven that it works,
www.carabos.com | I haven't tested it. -- Donald Knuth
More information about the SciPy-User
mailing list