14-p14_sqrt求平方根


def y(x, a):
    return (x**2 - a) ** 2


def dy_dx(x, a):
    return 2 * (x**2 - a) * 2 * x


def dx(x, a, alpha):
    return - dy_dx(x, a) * alpha

import numpy as np
x = np.random.uniform(0.1, 2)

for _ in range(1000):
    x += dx(x, 2, 0.01)

print(x)

D:\Anaconda\python.exe D:/AI20/06_codes/deeplearning_20/p14_sqrt.py
1.4142135623730956

Process finished with exit code 0

发布了88 篇原创文章 · 获赞 2 · 访问量 1303

猜你喜欢

转载自blog.csdn.net/HJZ11/article/details/104506972
今日推荐