查看“Python TensorFlow Basics”的源代码
←
Python TensorFlow Basics
跳转至:
导航
、
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只对以下1个用户组开放:
用户
。
您可以查看并复制此页面的源代码:
=讲课= 斯坦福大学教程Lecture 1和Lecture 2 回归模型 regression model(Lecture 1) 线性回归 linear model(Lecture 2) =IPython= * IPython 命令行输入:$ ipython notebook 或者使用:$jupyter notebook =Python Math library= https://docs.python.org/3.6/library/math.html ==matplotlib== (matplotlib/pyplot)展示WaveForm AudioPlot <code> import matplotlib.pyplot as plt from wavReader import readWav rate, data =readWav('c:\\Users\\icenter\\Documents\\a.wav') plt.plot(data) plt.show() </code> == sigmoid== (http://matplotlib.org/) import matplotlib.pyplot as plt import numpy as np x = np.linspace(-5,5,100) sigmoid = lambda x: 1 / (1 + np.exp(-x)) plt.plot(x,sigmoid(x), color='red', lw=2) plt.show() ==softmax函数== import math import matplotlib.plot as plt w=[1,2,3,4,5,6,7,8,9] w_exp=[math.exp(i) for i in w] print(w_exp) sum_w_exp = sum(w_exp) softmax = [round(i / sum_w_exp, 3) for i in w_exp] print(softmax) print(sum(softmax)) plt.plot(softmax) plt.show() ---- =Tensorflow= TensorFlow:opensource machine intelligence libraries import tensorflow as tf import numpy A=tf.Variable([[1,2],[3,4]], dtype=tf.float32) A.get_shape() TensorShape([Dimension(2), Dimension(2)]) B=tf.Variable([[5,6],[7,8]],dtype=tf.float32) B.get_shape() TensorShape([Dimension(2), Dimension(2)]) C=tf.matmul(A,B) tf.global_variables() [<tf.Variable 'Variable:0' shape=(2, 2) dtype=float32_ref>, <tf.Variable 'Variable_1:0' shape=(2, 2) dtype=float32_ref>] init = tf.global_variables_initializer() sess =tf.Session() sess.run(init) print(sess.run(C)) [[ 19. 22.] [ 43. 50.]] print(sess.run(tf.reduce_sum(C, 0))) [ 62. 72.] print(sess.run(tf.reduce_sum(C, 1))) [ 41. 93.] =TensorFlow 的表示= ==Sigmoid 函数/SOFTMAX 函数/SOFTPLUS函数== (https://www.tensorflow.org/api_guides/python/nn) R=tf.Variable([1.,.2,3],dtype=tf.float32) T=tf.Variable([True, True, False, False], dtype=tf.bool) U=tf.Variable([True, True, True, False], dtype=tf.bool) init=tf.global_variables_initializer() sess.run(init) //sess.run(tf.global_variables_initializer()) print(sess.run(tf.sigmoid(R, name="last"))) print(sess.run(tf.softmax(R,dim=-1, name="last"))) print(sess.run(tf.nn.softplus(R,name="last"))) print(sess.run(tf.nn.relu(R,name="XXX"))) print(sess.run(tf.cast(T, tf.int32))) print(sess.run(tf.cast(T, tf.float32))) print(sess.run(tf.reduce_mean(tf.cast(T, tf.float32)))) ==Tensorflow的reshape函数== tf.reshape() Y=tf.Variable([[1,2,3],[4,5,6]],dtype=tf.float32) sess.run(tf.global_variables_initializer()) print(sess.run(Y)) [[1 2 3] [4 5 6]] print(sess.run(tf.reshape(Y,[6]))) [ 1. 2. 3. 4. 5. 6.] print(sess.run(tf.reshape(Y,[3,2]))) <nowiki>array([[1 2] [3 4] [5 6]], dtype=float32) </nowiki> print(sess.run(tf.reshape(Y,[-1]))) array([1 2 3 4 5 6],dtype=float32) print(sess.run(tf.reshape(Y, [-1,1]))) <nowiki> array([[ 1.], [ 2.], [ 3.], [ 4.], [ 5.], [ 6.]], dtype=float32) </nowiki> =tf.argmax= tf.argmax is an extremely useful function which gives you the index of the highest entry in a tensor along some axis. print(sess.run(tf.argmax(Y,1))) [2 2] print(sess.run(tf.argmax(Y,0))) [1 1 1] =TensorFlow Saver= # Add ops to save and restore all the variables. saver = tf.train.Saver() # Save the variables to disk. save_path = saver.save(sess, "/tmp/model.ckpt") print("Model saved in file: %s" % save_path) saver.restore(sess, "/tmp/model.ckpt") print("Model restored.") # Do some work with the model # current file path import os os.path.realpath('.') =线性代数 Linear Algebra= matrix(matrices) and vector(vectors) addition and scalar multiplication Matrix and vector multiplication matrix and matrix multiplication matrix inverse/transpose (https://www.tensorflow.org/api_docs/python/tf/matrix_inverse) (https://www.tensorflow.org/api_guides/python/math_ops) =Octave = 展示Sigmoid函数和Softplus函数 x = -5:0.1:5 plot(x, y=1 ./(1+e.^-x) plot(x, z = log(1+e.^x))
返回
Python TensorFlow Basics
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
实践教学
个性化3D设计与实现
人工智能实践教学
区块链技术及应用
虚拟现实技术与内容制作
超越学科界限的认知基础课程
电子工艺实习
Nand2Tetris Engine Curriculum
TULLL Creative Learning Group
Wiki上手说明
Wiki账户创建
最近更改
工具
链入页面
相关更改
特殊页面
页面信息