[SciPy-user] Understanding numpy array operations

Pauli Virtanen pav@iki...
Tue Nov 4 15:59:41 CST 2008


Tue, 04 Nov 2008 13:39:36 -0800, Lou Pecora wrote:
[clip] 
> for j in range(n):
>    for i in range(n):
>       A[i+n*j] = i*u + j*v
>
> # This is a double loop, but I suspect there is something wrong or
> # missing What are u and v?  The indexing on A is for returning an
> # entire row, but it will go beyond the bounds of A.  I can't figure
> # this one out. Sorry.

It actually won't go out-of-bounds, the loops go through i=0, 1, ..., n-1
and same for j -- which is in the range >= 0 and < n*n. If 'u' and 'v' 
are vectors of length 3, the row "(i+n*j)" will after the loops contain 
the vector "i*u + j*v".

-- 
Pauli Virtanen



More information about the SciPy-user mailing list