# [SciPy-user] Transforming 1-d array to 2-d array

Rich Shepard rshepard@appl-ecosys....
Mon Feb 26 22:35:14 CST 2007

```On Mon, 26 Feb 2007, Dave wrote:

> #Define the data to put in the upper-diagonal part of the array
> myData = rand(N*(N-1)/2)
>
> #Create an index to the upper-diagonal part
> idx = triu(ones([8,8])-eye(8)).nonzero()
>
> #Instantiate a zero array and populate the upper-triangular part with myData
> A = zeros([N,N],dtype=float)
> A[idx] = myData
>
> #Place ones on the diagonal
> A += eye(N)

Dave,

Now I need a bit more guidance, to complete the symmetrical matrices.

Instead of 'myData' above, my starting arrays are barEco, barNat, and
barSoc. They are the upper halves of the matrix 'A' above, with 1s in the
diagonal.

I created an index to the lower-diagonal part:
udx = tril(ones([8,8])-eye(8)).nonzero()

And used them to produce the bottom halves with 1s as the diagonal; for
example:

[[ 1.          0.          0.          0.          0.          0.  	    0. 		0.]
[ 0.4365366   1.          0.          0.          0.          0.           0.          0.]
[ 0.47069221  0.32643563  1.          0.          0.          0.  	    0.          0.]
[ 0.34658848  0.30102352  0.33747359  1.          0.          0.  	    0.          0.]
[ 0.31984748  0.35513807  0.30939894  0.40102534  1.          0.  	    0.          0.]
[ 0.40086694  0.348865    0.36086516  0.44149988  0.4015585   1.           0.          0.]
[ 0.35568232  0.40615208  0.35659227  0.34946598  0.32117778  0.50985137   1.          0.]
[ 0.2988847   0.30538231  0.34382488  0.34632516  0.39801757  0.34285765   0.33620439  1.]]

Now, my question is how to combine the upper half ('A', above) with the
lower half leaving only one diagonal with 1s.

I've tried several ways, but they're all incorrect: they don't work and
python complains.

Rich

--
Richard B. Shepard, Ph.D.               |    The Environmental Permitting
Applied Ecosystem Services, Inc.        |          Accelerator(TM)
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
```