[Numpy-discussion] Complex slicing and take

Eric Emsellem eemselle at eso.org
Wed Dec 30 18:05:17 EST 2009


Thanks!

will try that and see how the performance varies depending on the size
of my arrays.

thanks again!
Eric
> Constructing big intermediate arrays, might not improve performance
> compared to a loop
> 
>>>> >>> np.arange(30).reshape(6,5)
> array([[ 0,  1,  2,  3,  4],
>        [ 5,  6,  7,  8,  9],
>        [10, 11, 12, 13, 14],
>        [15, 16, 17, 18, 19],
>        [20, 21, 22, 23, 24],
>        [25, 26, 27, 28, 29]])
> 
>>>> >>> np.arange(30).reshape(6,5)[np.array([[1,2,2,1]]).T,np.arange(0,3)+np.array([[0,1,2,1]]).T]
> array([[ 5,  6,  7],
>        [11, 12, 13],
>        [12, 13, 14],
>        [ 6,  7,  8]])
> 
>>>> >>> np.arange(30).reshape(6,5)[np.array([[1,2,2,1]]).T,np.arange(0,3)+np.array([[0,1,2,1]]).T].sum(0)
> array([34, 38, 42])
> 
> Josef



More information about the NumPy-Discussion mailing list