Great! Thank you!

On 16/09/2011 17:43, Warren Weckesser wrote:
> 
> 
> On Fri, Sep 16, 2011 at 10:18 AM, Benjamin Landenberger
> <benjamin.landenber...@imtek.uni-freiburg.de
> <mailto:benjamin.landenber...@imtek.uni-freiburg.de>> wrote:
> 
>     Hello list!
> 
>     I have an array *mask* of shape (a, b) and another array *intensities*
>     of shape (N, a, b), where the values in *mask* range from 0 to N-1. It
>     is somehow similar to label arrays in scipy.ndimage.
> 
>     Now I want to pick those entries from the first dimension of
>     *intensities* which are given by *mask*. The returned array shall again
>     wave shape (a, b).
> 
>     Can this be done with fancy indexing?
> 
> 
> 
> The choose() function can be used:
> 
>  In [19]: intensities
> Out[19]:
> array([[[ 1,  2,  3],
>         [ 4,  5,  6],
>         [ 7,  8,  9]],
> 
>        [[11, 12, 13],
>         [14, 15, 16],
>         [17, 18, 19]],
> 
>        [[21, 22, 23],
>         [24, 25, 26],
>         [27, 28, 29]]])
> 
> In [20]: mask
> Out[20]:
> array([[0, 0, 1],
>        [1, 1, 1],
>        [1, 2, 2]])
> 
> In [21]: choose(mask, intensities)
> Out[21]:
> array([[ 1,  2, 13],
>        [14, 15, 16],
>        [17, 28, 29]])
> 
> 
> Warren
> 
> 
> 
>     Thank you,
> 
>     Ben
> 
>     _______________________________________________
>     NumPy-Discussion mailing list
>     NumPy-Discussion@scipy.org <mailto:NumPy-Discussion@scipy.org>
>     http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 
> 
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to