[MATRIX-SIG] problem with Statistics module

David Konerding dek@cgl.ucsf.edu
Wed, 17 Sep 97 13:24:26 -0700


Dear Konrad,

I have uncovered a small problem with using your
Statistics module: when using it on arrays of
type Object ('O'), standardDeviation will segfault.
I am using Python-1.4 with the latest version of NumPy.

The following program exhibits the error.

	import sys
	from Numeric import *
	from Statistics import *
	a = [    [ 1., 2., 3. ],
		 [ 4., 5., 6. ],
		 [ 7., 8., None ],
	]
	b = array(a)
	print b.typecode()
	c = array(b[0])
	print c.typecode()
	print average(c)
	print standardDeviation(c)

(I use Nones in my arrays to represent a time in which no
observation was made)

If the Python list doesn't contain the 'None', the array b
will be created as type Float, but since it has the None, it's created
as type Object.  When I extract a row from the matrix into a new
array, called c, it is created as type O, even though it only contains
floats.  Calling standardDeviation on an array of type Object causes the
segfault.  

The segfault appears to happen in sqrt() since apparently segfault 
isn't defined on the Object type:

	a = [ 1., 2., 3. ]
	b = array(a)
	print sqrt(b)
	c = array(a, 'O')
	print c
	print sqrt(c) ## line 34

gives:

[ 1.          1.41421356  1.73205081]
[1.0  2.0  3.0 ]
Traceback (innermost last):
  File "<stdin>", line 34, in ?
AttributeError: attribute-less object


I expect the best thing I can do here is cast the array
explicitly as type 'd' when I extract a row.  But I'd prefer that
NumPy didn't segfault.

Dave
-----------------------------------------------------------------------------
Email: dek@cgl.ucsf.edu   David Konerding   WWW: http://picasso.ucsf.edu/~dek
-----------------------------------------------------------------------------

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________