#1 output.py line 83 divide by 0

closed-fixed
None
5
2003-11-05
2003-07-11
Anonymous
No

Marion.Sturtevant@state.or.us
Here's the relevant code
with comment describing
what goes wrong.
Initialize
max_histo_y_val to 1 instead of -999 to fix.
#
=============================================================================

def
histogram(results_dict, file_name=None):
"""Print or save a
histogram for the data stored in the results dictionary.

The
routine sums up the number of record pairs with matching weights
for
each integer value of matching weights.

If a file
name is given, the output will be written into this text file.

"""

histo = {} # Start with an empty histogram
dictionary

min_histo_x_val = 9999 # Minimum X axis value
in the histogram
max_histo_x_val = -999 # Maximum X axis
value in the histogram
max_histo_y_val = -999 # Maximal Y axis
value in the histogram

# Loop over all record dictionaries - - - - - - - - - - - - - - - - - - - - -

#
for (rec_num, rec_dict) in
results_dict.items():

weights = rec_dict.values() # Only
the weight values are needed

# Suppose weights
contains only:
#
[29.736308653623112][12.989151540086517]
# No more
than one of each weight.
# Then w_count will always be 0, and
when we set scale_factor_y
# below, we divide by
0.
#

for w in weights:
w_int = int(round(w)) #
Round to closest integer

w_count =
histo.get(w_int,0)
histo[w_int] = w_count+1 # Increase
count by one

if (w_count > max_histo_y_val):

max_histo_y_val = w_count

# Sort histogram according
to X axis values
#
x_vals = histo.keys()
y_vals =
histo.values()

histo_list = map(None, x_vals,
y_vals)
histo_list.sort()

scale_factor_y = 70.0 /
max_histo_y_val

Discussion

  • Peter Christen
    Peter Christen
    2003-11-05

    • assigned_to: nobody --> christenp
    • status: open --> closed-fixed