Numerical Python Question

Carl Banks imbosol at vt.edu
Wed Oct 16 15:05:40 EDT 2002


Uwe Schmitt wrote:
> 
> Hi,
> 
> I tried (similar to MatLab):
> 
>   dest[:n] = greater( orig1[:n], orig2[:n])
> 
> which does not work, the assignment with a sliced array
> on the left side seams not to be implemented.


It seems to work for me (using 2.1.3).  Are you sure: the arrays are
rank-compatible (i.e. dest, orig1, and orig2 are all of same rank?  n
is an integer?  dest has been previously defined?


Python 2.1.3 (#1, Apr 20 2002, 10:14:34) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> from Numeric import *
>>> a = zeros((10,),Float)
>>> b = ones((10,),Float)
>>> c = zeros((10,),Int)
>>> a
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
>>> b
array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])
>>> c
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> c[:5] = greater(b[:5],a[:5])
>>> c
array([1, 1, 1, 1, 1, 0, 0, 0, 0, 0])


-- 
CARL BANKS
http://www.aerojockey.com



More information about the Python-list mailing list