Re: OverflowError: math range error...

2006-06-23 Thread Sheldon
Thanks for the tips!
I am going to look into this some more.

/Sheldon

Simon Forman skrev:

 Sheldon wrote:
  Hi,
 
  I have a written a script that will check to see if the divisor is zero
  before executing but python will not allow this:
 
  if statistic_array[0:4]  0.0:
  statistic_array[0,0:4] =
  int(multiply(divide(statistic_array[0,0:4],statistic_array \
  [0,4]),1.0))/100.0
 
  Does anyone know why Python is complaining:
 
  statistic_array[0,0:4] =
  int(multiply(divide(statistic_array[0,0:4],statistic_array[0,4]),1.0))/100.0
 
  OverflowError: math range error
 
  and how do I get around this problem? This stupid because there is a if
  statement preventing this dividing by zero.
 
  Sincerely,
  Sheldon

 I don't know what special math modules you're using, but python usually
 raises ZeroDivisionError for divide-by-zero problems.

 Try printing the intermediate values of each step in your problem code.

 d = divide(statistic_array[0,0:4], statistic_array[0,4])
 print d

 m = multiply(d, 1.0)
 print m

 i = int(m)
 print i

 statistic_array[0,0:4] = i
 
 
 That might help you track down what's wrong.

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: OverflowError: math range error...

2006-06-23 Thread Sheldon
Thanks for the tips!
I am going to look into this some more. I am not used to using Numeric
and the logical functions. I didn't think about what you pointed out
and somewhere the returned values from these logical methods are not
what I expect.  I will rewrite the whole thing using alltrue instead.

/Sheldon

Robert Kern skrev:

 Sheldon wrote:
  Hi,
 
  I have a written a script that will check to see if the divisor is zero
  before executing but python will not allow this:
 
  if statistic_array[0:4]  0.0:
  statistic_array[0,0:4] =
  int(multiply(divide(statistic_array[0,0:4],statistic_array \
  [0,4]),1.0))/100.0
 
  Does anyone know why Python is complaining:
 
  statistic_array[0,0:4] =
  int(multiply(divide(statistic_array[0,0:4],statistic_array[0,4]),1.0))/100.0
 
  OverflowError: math range error
 
  and how do I get around this problem? This stupid because there is a if
  statement preventing this dividing by zero.

 What kind of arrays are you using? If it's Numeric (and I think it is because
 numarray and numpy would throw an error at the if: statement), then your test 
 is
 incorrect.

 Comparisons yield arrays of boolean values. When a Numeric boolean array is 
 used
 as a truth value (like in an if: statement), then it will return True is *any*
 of the values are True. Use Numeric.alltrue(statistic_array[:4]  0.0) 
 instead.

 Both numarray and numpy throw an exception when one attempts to use arrays as
 truth values since the desired meaning (alltrue or sometrue) is ambiguous.

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
-- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: OverflowError: math range error...

2006-06-22 Thread Simon Forman
Sheldon wrote:
 Hi,

 I have a written a script that will check to see if the divisor is zero
 before executing but python will not allow this:

 if statistic_array[0:4]  0.0:
 statistic_array[0,0:4] =
 int(multiply(divide(statistic_array[0,0:4],statistic_array \
 [0,4]),1.0))/100.0

 Does anyone know why Python is complaining:

 statistic_array[0,0:4] =
 int(multiply(divide(statistic_array[0,0:4],statistic_array[0,4]),1.0))/100.0

 OverflowError: math range error

 and how do I get around this problem? This stupid because there is a if
 statement preventing this dividing by zero.

 Sincerely,
 Sheldon

I don't know what special math modules you're using, but python usually
raises ZeroDivisionError for divide-by-zero problems.

Try printing the intermediate values of each step in your problem code.

d = divide(statistic_array[0,0:4], statistic_array[0,4])
print d

m = multiply(d, 1.0)
print m

i = int(m)
print i

statistic_array[0,0:4] = i


That might help you track down what's wrong.

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: OverflowError: math range error...

2006-06-22 Thread Robert Kern
Sheldon wrote:
 Hi,
 
 I have a written a script that will check to see if the divisor is zero
 before executing but python will not allow this:
 
 if statistic_array[0:4]  0.0:
 statistic_array[0,0:4] =
 int(multiply(divide(statistic_array[0,0:4],statistic_array \
 [0,4]),1.0))/100.0
 
 Does anyone know why Python is complaining:
 
 statistic_array[0,0:4] =
 int(multiply(divide(statistic_array[0,0:4],statistic_array[0,4]),1.0))/100.0
 
 OverflowError: math range error
 
 and how do I get around this problem? This stupid because there is a if
 statement preventing this dividing by zero.

What kind of arrays are you using? If it's Numeric (and I think it is because 
numarray and numpy would throw an error at the if: statement), then your test 
is 
incorrect.

Comparisons yield arrays of boolean values. When a Numeric boolean array is 
used 
as a truth value (like in an if: statement), then it will return True is *any* 
of the values are True. Use Numeric.alltrue(statistic_array[:4]  0.0) instead.

Both numarray and numpy throw an exception when one attempts to use arrays as 
truth values since the desired meaning (alltrue or sometrue) is ambiguous.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth.
   -- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list