From: Darren D. <dd...@co...> - 2004-10-04 15:03:32
|
On Monday 04 October 2004 10:38 am, you wrote: > On Monday 04 October 2004 00:58, Darren Dale wrote: > > Would somebody kindly direct me to some information on how to deal with > > dividing by zero? I am getting ValueError: math domain error, is there > > anything I can do to return an inf instead? > > > > Thanks, > > > > Darren > > If you can't avoid the division by zero, you can handle the exception: > > try: > a = x/0 > except ValueError: > pass # or some other outcome (a = 'inf') > > as far as I know python does not have a representation for infinity. (if I > am wrong, somebody please correct me) There are some special representations that can be imported, for example from numarray.ieeespecial import inf However, My simulations require HEAVY array mathematics, so I dont have an opportunity to test for exceptions. Darren |