Since moving to numpy I've had a few problems with my existing

code. It basically revolves around the numpy scalar types. e.g.

------------------------------------------------

array([[0, 1],>>import Numeric as N

a = N.array([[0,1],[2,3]])

a

[2, 3]])

Traceback (most recent call last):>>i = a[0,0]

1/i

File "<pyshell#30>", line 1, in -toplevel-

1/i

ZeroDivisionError: integer division or modulo by zero

array([[ 0. , 1.5],>>b = a * 1.5

b

[ 3. , 4.5]])

array([[ 0., 1.],>>N.floor(b)

[ 3., 4.]])

================================>>================================ RESTART

array([[0, 1],>>import numpy as N

a = N.array([[0,1],[2,3]])

a

[2, 3]])

0>>i = a[0,0]

1/i

array([[ 0. , 1.5],>>b = a * 1.5

b

[ 3. , 4.5]])

array([[ 0., 1.],>>N.floor(b)

[ 3., 4.]])

array([[0, 1],>>a = N.array([[0,1],[2,3]], dtype='O')

a

[2, 3]], dtype=object)

Traceback (most recent call last):>>i = a[0,0]

1/i

File "<pyshell#45>", line 1, in -toplevel-

1/i

ZeroDivisionError: integer division or modulo by zero

array([[0.0, 1.5],>>b = a * 1.5

b

[3.0, 4.5]], dtype=object)

Traceback (most recent call last):>>N.floor(b)

File "<pyshell#48>", line 1, in -toplevel-

N.floor(b)

AttributeError: 'float' object has no attribute 'floor'

---------------------------------------------->>>

An additional problem involves classes that have e.g. __rmul__ methods

defined and are sufficiently similar to numpy arrays that my classes'

__rmul__ methods are not invoked when using numpy scalars.

Using the 'O' dtype gives me Python types that raise zero division

errors appropriately (for my code) and the desired calls to e.g.

__rmul__ methods, but reduced functionality in other repects.

I might (I hope) be missing something obvious; but it seems like, to be

safe, I'm going to have to do a lot of explicit conversions to Python

types (or abandon catching zero division errors, and documenting some of

my classes to highlight that whether scalar * a equals a * scalar

depends on whether a.__rmul__ is called, which depends on the type of

scalar).

I suppose I might get round both issues by subclassing existing numpy

dtypes. Any ideas? Cheers. TIA.

Duncan