Hi all, I have some trouble with the new numarray library. Most of the time the numarray code prints out some negative value whereas the Numeric code yields positive values. This behaviour justs shows up when using large arrays. Can anybody point out what I need to change in the numarray version to get the Numeric behaviour? System: WinXP, python2.3.4, Numeric23.5, numarray1.1.1 ----- NUMARRAY-VERSION: from numarray import greater, reshape, trace from numarray.random_array import standard_normal n=1000 A = greater(standard_normal(n*n), 0.9) A = reshape(A, (n, n)) print trace(A) ----- NUMERIC-Version: from Numeric import greater, reshape, trace from RandomArray import standard_normal n=1000 A = greater(standard_normal(n*n), 0.9) A = reshape(A, (n, n)) print trace(A) ----- Thank you for your help. Gerald
Most of the time the numarray code prints out some negative value whereas the Numeric code yields positive values.
numarray.greater() returns a Bool array, while Numeric.greater() returns a 32-bit integer array. Try this code: import numarray as na import Numeric as nu print na.greater([0.1,0.9],0.5).type() print nu.greater([0.1,0.9],0.5).typecode() ## prints an 'ell' for n in range(126,131): A=na.ones((n,n)).astype(na.Bool) B=nu.ones((n,n)).astype('1') ## that's a one print n,na.trace(A),nu.trace(B) The problem is overflow in the addition of 8 bit signed integers; it occurs in both numarray and Numeric, given the right array type. The snippet below should give you some idea of how to find what you want: from numarray import * from numarray.random_array import standard_normal A=standard_normal((1000,1000)) > 0.9 print len(nonzero(diagonal(A))[0]) print trace(A.astype(Int32)) Cheers, Rory
participants (2)
-
Rory Yorke
-
Rosenfellner Gerald VAI.ISC 1