[SciPy-user] Combining Arrays

Rich Shepard rshepard@appl-ecosys....
Tue Feb 27 13:09:37 CST 2007


   I have two arrays: one is the upper triangular half with 1s in the
diagonal, the other has the values for the lower triangular half. I also
have an array that specifies how the values in the lower half array are to
be assigned to rows and columns of the 2D array. However, as this is my
first use of NumPy, I am stuck at how to put these together to form what I
need.

   Here's the upper array (call it topArr):

[[ 1.          2.29075869  2.12453058  3.06339111  2.88526612  3.32199956
    2.96319486  3.12649018]
  [ 0.          1.          2.81580625  3.23207315  2.493608    2.49459335
    2.86643834  2.77111816]
  [ 0.          0.          1.          2.26500627  2.4902972   2.81149761
    2.46213192  2.80432329]
  [ 0.          0.          0.          1.          2.86150888  3.1135404
    1.96135592  3.34577184]
  [ 0.          0.          0.          0.          1.          3.27458386
    2.90845738  2.88745987]
  [ 0.          0.          0.          0.          0.          1.
    2.51245188  2.91666234]
  [ 0.          0.          0.          0.          0.          0. 
1.
    2.97438117]
  [ 0.          0.          0.          0.          0.          0. 
0.
    1.        ]]

   Here's the lower array (call it botArr):

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

   And, using 'udx = tril(ones([8,8])-eye(8)).nonzero()' this is udx:

(array([1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7,
        7, 7, 7, 7, 7]), array([0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4,
0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6]))

   What I need is the array:

[[ 1.00		2.29	2.12	3.06 	...	]
  [ 0.44		1.00	2.82	3.23	...	]
  [ 0.47		0.22	1.00	2.26	...	]
 		...
 						]]

   How do I do this, please?

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


More information about the SciPy-user mailing list