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

Rich Shepard rshepard@appl-ecosys....
Sun Feb 25 16:16:52 CST 2007


   I have this array (called barEco):

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

and I want to convert it to:

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

with 1.00 as the diagonal.

   It appears that the eye() function is the tool, but when I try

 	foo = eye(barEco,8,8,1)
 	print foo

python responds

Traceback (most recent call last):
   File "/data1/eikos/scopingPage.py", line 184, in OnCalcWeights
     inpWts = functions.weightcalc()
   File "/data1/eikos/functions.py", line 164, in weightcalc
     foo = eye(barEco,8,8,1)
   File "/usr/lib/python2.4/site-packages/numpy/lib/twodim_base.py", line 48,
in eye
     m = equal(subtract.outer(arange(N), arange(M)),-k)
TypeError: only length-1 arrays can be converted to Python scalars

   So, either I used eye() incorrectly, or that's not how to make the
conversion. What should I be doing?

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