标签:div 高级 取数 开源软件 ble 网络 rate 指定 edm
Google的开源软件库
线:节点之间的输入输出关系,线上运输张量. tensor:张量- 指代数据
"""
不同方式求解 1 + 1/2 + 1/2^2 + 1/2^3 + ...... + 1/2^50
"""
# 1. tensorflow 1.*求解
import tensorflow as tf
print(tf.__version__)
x = tf.Variable(0.)
y = tf.Variable(1.)
add_op = x.assign(x + y)
div_op = y.assign(y / 2)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for iteration in range(50):
sess.run(add_op)
sess.run(div_op)
print(x.eval())
# 2. pytorch 求解
import torch
print(torch.__version__)
x = torch.Tensor([0.])
y = torch.Tensor([1.])
for iteration in range(50):
x = x + y
y = y / 2
print(x)
# 3. tensorflow 2.0 求解
import tensorflow as tf
print(tf.__version__)
x = tf.constant(0.)
y = tf.constant(1.)
for iteration in range(50):
x = x + y
y = y / 2
print(x.numpy())
# 4. 纯python求解
x = 0
y = 1
for iteration in range(50):
x = x + y
y = y / 2
print(x) # 精度有点不一样
标签:div 高级 取数 开源软件 ble 网络 rate 指定 edm
原文地址:https://www.cnblogs.com/hp-lake/p/12008559.html