tensorflow 学习笔记1

import tensorflow as tf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import  datasets
import requests

#iris = datasets.load_iris()
#print(len(iris.data))
#print(len(iris.target))
birthdata_url = 'https://www.umass.edu/statdata/statdata/data/lowbwt.dat'
birthfile = requests.get(birthdata_url)
birth_data = birthfile.text.split('\'r\n') [5:]

zero = tf.zeros([5,5])
filled_tsr = tf.fill([5,5],100)
constant_tsr = tf.constant(10.0,tf.float32,shape= [5,5,5])
M = tf.zeros_like(constant_tsr)
my_val = tf.Variable(tf.zeros([2,3]))
"""
tf.linspace(start=0 , stop  = 1 , step = 3) include the stop value  return [0 0.5 1]
while tf.range(start = 0 , stop = 9 ,step = 3) don't include the stop value return [0 3 6]
"""
'''
tf.random_uniform([row_dim , col_dim], minval, maxval) make a uniform randomization 
tf.random_normal([row_dim , col_dim], mean , stddev ) make a Guassian randomization
tf.truncated_normal([row_dim , col_dim], mean , stddev ) make a Guassian randomization that all of the value are in the 
    range of [mean-stddev , mean + stddev]


tf.random_crop(input_tensor, output_size)
tf.random_shuffle(input_tensor)

my_var = tf.Variable(tf.zeros([row_dim , col_dim]))
tf.convert_to_tensor() can used to transfer a numpy array to  list or a constant value to a tensor
'''




'''
    with tf.Session() as sess:
    
        initialize_op = tf.global_variables_initializer()
        sess.run(initialize_op)
        print(sess.run(zero))
        x = tf.placeholder(tf.float32, shape= [2,2])
        y = tf.identity(x)
        x_val = np.random.rand(2,2)
        t = sess.run(y ,feed_dict={x:x_val})
        print(type(t))
'''


"""
    initialize_op = tf.global_variables_initializer()
    sess.run(initialize_op)
the upper program can be used to make all the variable before it initialized
    t = sess.run(y ,feed_dict={x:x_val})
in this part t is a <class 'numpy.ndarray'>


tf.matmul(A,B) make a matrix mutiplication
tf.transpose(A) make a A.T
tf.matrix_determinat(A) make a det of A (also present as |A| )
tf.matrix_inverse(A) make a inverse of A 
tf.cholesky(A) 
tf.self_adjoint_eig(A) make a 
"""

with tf.Session() as sess:
    A = np.array((-2,3,9))
    B = tf.constant([-2,3,8])
    C = tf.placeholder(tf.float32 , shape=B.shape)
    print(sess.run(tf.nn.relu6(C),feed_dict={C:A}))

"""
The Activation Functions:
    tf.nn.softsign()  return to the x/(abs(x)+1)
    tf.nn.softplus()  return to the log(exp(x)+1)
    tf.nn.elu()       return to the exp(x)+1 if x<0 else x  (Exponential Linear Unit)
"""

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值