Items tagged with array

Feed

Given a list L of n^2 integers, I can fill an nxn matrix through Matrix(n,n,L).  for instance:
n := 4:
L := [$1..n^2]:
A := Matrix(n,n, L);

I don't know how to do this with a 0-based Array.  I wished that as in the case of the Matrix, the command
B := Array(0..n-1, 0..n-1, L);
would assign B[0,0]=1, B[0,1]=2, ..., B[3,3]=16, but it doesn't.

I know how to fill B's entries through doubly nested for-loops but I suspect that there might be a clever way of doing that. If so, then please show me how.

 

hello, For the P, and A arrays which depend on i,j, it always gives me index out of range i dont know whats wrong, any help, and thank you
 

 

restart

N:=4000;
g:=Array(0..N):
g[0]:=0:
g[1]:=-2.47:
g[2]:=-2.33:
g[3]:=0.205:
g[4]:=2.99:
g[5]:=2.66:
g[6]:=2.65:
g[7]:=2.59:
g[8]:=2.5:
g[9]:=2.42:
g[10]:=2.37:
g[11]:=2.37:
g[12]:=2.39:
g[13]:=2.42:
g[14]:=2.43:
g[15]:=2.42:
g[16]:=2.4:
g[17]:=2.39:
g[18]:=2.39:
g[19]:=2.39:
g[20]:=2.38:
g[21]:=2.37:
g[22]:=2.36: