[Numpy-discussion] How to do : x[i,j] = y[k, j] with k = i+sj

Robert Kern robert.kern@gmail....
Mon Oct 27 12:51:39 CDT 2008


On Mon, Oct 27, 2008 at 10:38, Nicolas ROUX <nicolas.roux@st.com> wrote:
> Hi,
>
> Me again ;-)
> I have now a new question to ask (I hope not too silly).
>
> How to do :
>
> for j in range(yHeight):
>   for i in range(xWidth):
>      x[j,i] = y[k,i] with k = numpy.mod(i+sj,yHeight)
>
> With efficient numpy code, without the double "for" ?

j, i = numpy.ogrid[:yHeight, :xWidth]
k = (i+j) % yHeight
x = y[k,i]

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the Numpy-discussion mailing list