#show graph compaing the time taken to each implementation showgraph(t3,t4,t4/t3) show…
- User
#show graph compaing the time taken to each implementation showgraph(t3,t4,t4/t3)
show the graph comparing the time taken by each implementations
def showgraph(t3,t4,speedupfactor): # Create a figure for plotting fig = plt.figure()
code# Plot the data # pylab cannot plot arrays as numpy array so must first convert plt.plot([1, 2, 3, 4], t3, 'ro-', label = 'Recursive') # y is number of 1000 runs plt.plot([1, 2, 3, 4], t4, 'bo-', label = 'Iterative') plt.plot([1, 2, 3, 4], speedupfactor, 'go-', label = 'speedup') # Add a label to the x-axis plt.xlabel('Number of disks') # Add a label to the y-axis plt.ylabel('time (s)') # Add a title to the plot plt.title('graph of time taken by each implementation using recursive and iterative function') # Display legend plt.legend() # Display plot plt.show()runs the program
main() main() File "c:\Users\laboratorio\Downloads\Untitled-1.py", line 109, in main showgraph(t3,t4,t4/t3)
^ZeroDivisionError: float division by zero - Assistant
It seems like you are trying to divide
t4byt3, but one or both of these arrays contain zero values, resulting in aZeroDivisionError.To fix this issue, you can use
numpy.divide()with thewhereparameter to avoid division by zero. Here's the modifiedshowgraphfunction:python
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.