與常用c語言一樣品嚣,我們可以把Tensorflow看成是一種基本數(shù)據(jù)語言,
有常量,變量是晨,占位符等。
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 5 22:14:32 2019
@author: Administrator
"""
import tensorflow as tf
sess=tf.Session()
#常量
t1 = tf.constant([4.0],tf.float32)
print(sess.run(t1))
t2 = tf.constant([4.0,3],tf.float32)
print(t2)
print(sess.run(t2))
t3 = tf.zeros([1,2],tf.float32)
print(t3)
print(sess.run(t3))
t4 = tf.ones([1,2],tf.float32)
print(t4)
print(sess.run(t4))
#創(chuàng)建具有不同分布的隨機張量
'''
random_normal(
shape,
mean=0.0,
stddev=1.0,
dtype=tf.float32,
seed=None,
name=None
)
從正態(tài)分布中輸出隨機值.
參數(shù):
shape:一維整數(shù)張量或 Python 數(shù)組.輸出張量的形狀.
mean:dtype 類型的0-D張量或 Python 值.正態(tài)分布的均值.
stddev:dtype 類型的0-D張量或 Python 值.正態(tài)分布的標準差.
dtype:輸出的類型.
seed:一個 Python 整數(shù).用于為分發(fā)創(chuàng)建一個隨機種子.查看 tf.set_random_seed 行為.
name:操作的名稱(可選).
'''
t5 = tf.random_normal([1,2],mean=0.0,stddev=1 , dtype=tf.float32)
print(t5)
print(sess.run(t5))
#變量
def weight_variables(shape):
initial = tf.random_normal(shape,mean=0,stddev=1,dtype=tf.float32)
return tf.Variable(initial)
t6 = weight_variables([10,10])
print(t6)
def bias_variables(shape):
initial = tf.constant(0,shape=shape)
return tf.Variable(initial)
t7 = bias_variables([10])
print(t7)
#占位符
x = tf.placeholder("float", shape=[None, 784])
y_ = tf.placeholder("float", shape=[None, 10])