Reputation: 56
I'm doing a piece of work that is basically a random walk but with a probability of the person getting arrested after each step, n. I start with K people and then I have a graph which plots log(k) vs. n where k is the number of people that have survived n steps.
plt.plot(n,numpy.log(k)
I need to find the gradient of this graph but also want to do a line of best fit, any help would be most appreciated!
Upvotes: 3
Views: 1540
Reputation: 879411
a, b = np.polyfit(n, np.log(k), 1)
will return the coefficients of the best-fit line, logk = a n + b
.
Upvotes: 5