Berikut adalah perintah yang sering dipakai ketika menggunakan library TensorFlow.
import tensorflow as tf
hello = tf.constant('Hello ')
world = tf.constant('World')
with tf.Session() as sess:
result = sess.run(hello+world)
print(result)
#b'Hello World'
const = tf.constant(10)
matrix = tf.fill((4,4), 10)
myzeros = tf.zeros((4,4))
myones = tf.ones((4,4))
myrandn = tf.random_normal((4,4), mean=0, stddev=1)
myrandu = tf.random_uniform((4,4), minval=0, maxval=1)
myops = [const, matrix, myzeros, myones, myrandn, myrandu]
with tf.Session() as sess:
for op in myops:
print(sess.run(op), '\n')
"""
10
[[10 10 10 10]
[10 10 10 10]
[10 10 10 10]
[10 10 10 10]]
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]
[[-1.9242917 0.18743777 -0.34261355 -0.8634161 ]
[-1.1679807 -0.4038726 1.5690875 -0.01987255]
[ 1.1758449 0.3336661 0.19743773 1.1771116 ]
[-0.5213072 -0.15986288 -1.9592358 0.79677165]]
[[0.5947856 0.17603457 0.36953056 0.2571218 ]
[0.66753614 0.15850496 0.0251416 0.9134841 ]
[0.9150835 0.73837686 0.06361508 0.6473664 ]
[0.04934776 0.5074552 0.50578177 0.07426608]]
"""
a = tf.constant([[1,2],
[3,4]])
b = tf.constant([[10],[100]])
with tf.Session() as sess:
result = sess.run(tf.matmul(a, b))
print(result)
"""
[[210]
[430]]
"""
TensorFlow : Perintah Yang Sering Digunakan
Reviewed by noname needed
on
May 21, 2018
Rating:
No comments: