Skip to content

Commit

Permalink
variable
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYang1994 authored and YunYang1994 committed Mar 8, 2019
1 parent faedc0d commit e3abf2d
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 69 deletions.
129 changes: 129 additions & 0 deletions 1-Introduction/.ipynb_checkpoints/variable-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Variables are manipulated via the tf.Variable class.\n",
"# A tf.Variable represents a tensor whose value can be changed by running ops on it.\n",
"# Specific ops allow you to read and modify the values of this tensor.\n",
"\n",
"## Creaging a Variable"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor: <tf.Variable 'my/Variable:0' shape=() dtype=int32, numpy=1>\n",
"value: 1\n"
]
}
],
"source": [
"with tf.name_scope(\"my\"):\n",
" variable = tf.Variable(1)\n",
"print(\"tensor:\", variable)\n",
"print(\"value:\", variable.numpy())"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"## Using Variables\n",
"\n",
"# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"value: 2\n"
]
}
],
"source": [
"variable = variable + 1\n",
"print(\"value:\", variable.numpy())"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"## Using Variables\n",
"\n",
"# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"value: 3\n"
]
}
],
"source": [
"variable = tf.Variable(2)\n",
"variable.assign_add(1)\n",
"print(\"value:\", variable.numpy())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
69 changes: 0 additions & 69 deletions 1-Introduction/.ipynb_checkpoints/未命名-checkpoint.ipynb

This file was deleted.

129 changes: 129 additions & 0 deletions 1-Introduction/variable.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Variables are manipulated via the tf.Variable class.\n",
"# A tf.Variable represents a tensor whose value can be changed by running ops on it.\n",
"# Specific ops allow you to read and modify the values of this tensor.\n",
"\n",
"## Creaging a Variable"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor: <tf.Variable 'my/Variable:0' shape=() dtype=int32, numpy=1>\n",
"value: 1\n"
]
}
],
"source": [
"with tf.name_scope(\"my\"):\n",
" variable = tf.Variable(1)\n",
"print(\"tensor:\", variable)\n",
"print(\"value:\", variable.numpy())"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"## Using Variables\n",
"\n",
"# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"value: 2\n"
]
}
],
"source": [
"variable = variable + 1\n",
"print(\"value:\", variable.numpy())"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"## Using Variables\n",
"\n",
"# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"value: 3\n"
]
}
],
"source": [
"variable = tf.Variable(2)\n",
"variable.assign_add(1)\n",
"print(\"value:\", variable.numpy())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ This tutorial was designed for easily diving into TensorFlow2.0. it includes bo

#### 1 - Introduction
- **Hello World** ([notebook](1-Introduction/helloworld.ipynb)) ([code](1-Introduction/helloworld.py)). Very simple example to learn how to print "hello world" using TensorFlow.
- varible** ([notebook](1-Introduction/variable.ipynb)) ([code](1-Introduction/variable.py)). Learn to use variable in tensorflow.

0 comments on commit e3abf2d

Please sign in to comment.