Skip to content

Commit 453c4af

Browse files
committed
python code
0 parents  commit 453c4af

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// 将设置放入此文件中以覆盖默认值和用户设置。
2+
{
3+
// whitelist numpy to remove lint errors
4+
"python.linting.pylintArgs": [
5+
"--extension-pkg-whitelist=numpy"
6+
],
7+
"python.linting.pylintEnabled": false
8+
}

basic_usage.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#coding:utf-8
2+
import tensorflow as tf
3+
#import numpy as np
4+
matrix1 = tf.constant([[3., 3.]])
5+
matrix2 = tf.constant([[2.],[2.]])
6+
7+
product = tf.matmul(matrix1, matrix2)
8+
9+
sess = tf.Session()
10+
11+
result = sess.run(product)
12+
print(result)
13+
14+
sess.close()

first.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#coding:utf-8
2+
import tensorflow as tf
3+
import numpy as np
4+
5+
x_data = np.random.rand(100).astype("float32")
6+
y_data = x_data * 0.1 + 0.3
7+
8+
W = tf.Variable(tf.random_uniform([1],-1.0,1.0))
9+
b = tf.Variable(tf.zeros([1]))
10+
y = W * x_data + b
11+
12+
loss = tf.reduce_mean(tf.square(y-y_data))
13+
optimizer = tf.train.GradientDescentOptimizer(0.5)
14+
train = optimizer.minimize(loss)
15+
16+
init = tf.initialize_all_variables()
17+
18+
sess = tf.Session()
19+
sess.run(init)
20+
21+
for step in range(201):
22+
sess.run(train)
23+
if step % 20 == 0:
24+
print(step,sess.run(W), sess.run(b))

interactiveSession.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#coding:utf-8
2+
import tensorflow as tf
3+
sess = tf.InteractiveSession()
4+
5+
x = tf.Variable([1.0, 2.0])
6+
a = tf.constant([3.0, 3.0])
7+
8+
x.initializer.run()
9+
10+
sub = tf.subtract(x, a)
11+
print(sub.eval())
12+
13+
sess.close()

0 commit comments

Comments
 (0)