# [SciPy-user] Understanding numpy array operations

Lou Pecora lou_boog2000@yahoo....
Tue Nov 4 15:39:36 CST 2008

```OK, here's a shot:

n=5  # Pretty obvious, set n=5

A= reshape(zeros(5*3*n), (n*n,3))*1.0
# Start from the inside out.  zeros(5*3*n) give you a 1D array
# (not a matrix) of zeros 0.0 that has 75 0.0's. The reshape changes
# it to an array that is 25 rows by 3 columns (a 2D array). It is all
# multipled by 1.0 (which doesn't really change things in this case)
# and given the name A as a reference

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.

-- Lou Pecora,   my views are my own.

--- On Tue, 11/4/08, Evan Wilson <bandtheory@rocketmail.com> wrote:

> From: Evan Wilson <bandtheory@rocketmail.com>
> Subject: [SciPy-user] Understanding numpy array operations
> To: scipy-user@scipy.org
> Date: Tuesday, November 4, 2008, 3:59 PM
> Hello,
>
> I am a novice python/numpy user, using the language for
> computational physical science research.  I have been
> modifying scripts developed by another student who worked on
> the project before me.  However, I require a good
> understanding of what is actually happening in the code for
> when I go back to modify them.  I was wondering if anyone
> could tell me what the bit of code does:
>
>
> n
> = 5
> A
> = reshape(zeros(5*3*n), (n*n,3))*1.0
> for
> j in range(n):
>     for i in range(n):
>         A[i+n*j] = i*u + j*v
>
> I understand there are some matrix operations happening but
> I cannot tell what they do.  I would appreciate any help you
> could offer.
>
> Thanks,
>
> BT
>
>
>       _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

```