-
-
Notifications
You must be signed in to change notification settings - Fork 674
/
variable.py
36 lines (28 loc) · 1.02 KB
/
variable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env python
# coding=utf-8
#================================================================
# Copyright (C) 2019 * Ltd. All rights reserved.
#
# Editor : VIM
# File name : variable.py
# Author : YunYang1994
# Created date: 2019-03-08 00:36:23
# Description :
#
#================================================================
import tensorflow as tf
# Variables are manipulated via the tf.Variable class.
# A tf.Variable represents a tensor whose value can be changed by running ops on it.
# Specific ops allow you to read and modify the values of this tensor.
## Creaging a Variable
with tf.name_scope("my"):
variable = tf.Variable(1)
print("value:", variable.numpy())
## Using Variables
# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor
variable = variable + 1
print("value:", variable.numpy())
# To assign a value to a variable, use the methods assign, assign_add
variable = tf.Variable(2)
variable.assign_add(1)
print("value:", variable.numpy())