[Matrix-SIG] Numeric Array: adding a 0-D array to a cell in a 2-D array

Herbert L. Roitblat roitblat@hawaii.edu
Wed, 23 Feb 2000 20:51:06 -1000


Hey folks:
Here's my problem.  I am trying to transfer some programs to our Linux Alpha
box from our NT box.  In doing so, we have apparently updated versions of
things.  Here is something new for us to contend with.  A short program is
shown below:
(Numeric version 15.2 running on Linux on an Alpha Processor)

>>> from Numeric import *
>>> kwd=3
>>> jwd=3
>>> a=zeros((5,5),'b')
>>> a[kwd,kwd]=4
>>> a[kwd,kwd]=8
>>> temp=a[kwd,kwd]
>>> temp
8
>>> temp=temp+3
>>> temp
11
>>> a[kwd,kwd]=temp
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: Array can not be safely cast to required type
>>> type(temp)
<type 'array'>
>>> temp.shape
()

We get the type error from trying to set the matrix element with a matrix
element (apparently).  In the old version (1.9) on our NT box,
temp=a[kwd,kwd] results in temp being an int type.  How can we either cast
the temp to an int or enable what we really want, which is to add an int to
a[kwd,kwd], as in a[kwd,kwd] = a[kwd,kwd] + jwd ?

Do we have a bad version of Numeric?

Thanks very much,
Herb
Herbert L. Roitblat

PS: How'd we get from Numeric version 1.9 to 15.2 so fast?