[关闭]
@leona1992 2022-08-03T15:35:46.000000Z 字数 852 阅读 89

python 生成GIF动图

python openCV


网上找的code

  1. def gradient_descent(X_b, y, initial_theta, eta, n_iters=1e4, epsilon=1e-8):
  2. theta = initial_theta
  3. i_iter = 0
  4. xb = (np.array(X_b)[:, 1])
  5. while i_iter < n_iters:
  6. plt.ion()
  7. gradient = dJ(theta, X_b, y)
  8. last_theta = theta
  9. theta = theta - eta * gradient
  10. #while (i_iter % 1000) == 1:
  11. while (i_iter < 150) & ((i_iter % 5) == 1):
  12. print(i_iter)
  13. xq = [0, 2]
  14. yq = theta[0] * np.array(xq) + theta[1] * np.ones(np.shape(theta))
  15. fig = plt.figure()
  16. fig = plt.scatter((np.array(X_b)[:, 1]), y)
  17. fig = plt.plot(xq, yq, linewidth=4, color='darkgoldenrod')
  18. fig = plt.legend(['data', 'simulate'], loc='upper left')
  19. fig = plt.title('gradient')
  20. fig = plt.xlabel(i_iter)
  21. plt.savefig(r"C:\\Users\\xiaoy\\Pictures\\s\\" + format(i_iter+100) +
  22. '.png')
  23. plt.show()
  24. print(theta)
  25. plt.close()
  26. i_iter = i_iter + 1
  27. if (abs(J(theta, X_b, y) - J(last_theta, X_b, y)) < epsilon):
  28. break
  29. i_iter = i_iter + 1
  30. return theta
  31. theta = gradient_descent(X_b, y, initial_theta, eta)
  32. print("荣耀不朽")
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注