J'ai résumé les fonctions liées aux mathématiques qui sont principalement utilisées dans TensorFlow.
| une fonction | rôle | 
|---|---|
| tf.add(x, y, name=None) | Somme pour chaque élément | 
| tf.sub(x, y, name=None) | Différence entre les éléments | 
| tf.mul(x, y, name=None) | Produit de chaque élément | 
| tf.div(x, y, name=None) | Quotient élément par élément * Si le type numérique du tenseur est un type de fraction non flottante tel que int, il est tronqué après la virgule décimale.  | 
| tf.truediv(x, y, name=None) | Quotient élément par élément * Si le type numérique du tenseur est un type de nombre non flottant tel que int, convertissez-le d'abord en type virgule flottante.  | 
| tf.floordiv(x, y, name=None) | Quotient élément par élément * Si le type numérique du tenseur est un type à virgule flottante, le résultat est tronqué après la virgule décimale.  | 
| tf.mod(x, y, name=None) | Résidu pour chaque élément | 
Exemple d'utilisation)
vim arithmetic_operators.py
import tensorflow as tf
def add(j, k):
   _j = tf.constant(j)
   _k = tf.constant(k)
   result = tf.add(_j, _k)
   return result
def sub(j,k):
   _j = tf.constant(j)
   _k = tf.constant(k)
   result = tf.sub(_j,_k)
   return result
def mul(j,k):
   _j = tf.constant(j)
   _k = tf.constant(k)
   result = tf.mul(_j,_k)
   return result
def mod(j,k):
   _j = tf.constant(j)
   _k = tf.constant(k)
   result = tf.mod(_j,_k)
   return result
def div(j,k):
   _j = tf.constant(j)
   _k = tf.constant(k)
   result = tf.div(_j,_k)
   return result
with tf.Session() as sess:
     result = sess.run([mod(10,3)]) #10 %3 = 1
     result2 = sess.run([mul(5,4)]) #5 x 4 = 20
     result3 = sess.run([sub(10,6)]) #10 - 6 = 4
     result4 = sess.run([add(5,6)]) #5 + 6 =11
     result5 = sess.run([div(11.,7.)]) #11 / 7 = 1.5714285
     print result
     print result2
     print result3
     print result4
     print result5
résultat
python arithmetic_operators.py
[1]
[20]
[4]
[11]
[1.5714285]
| une fonction | rôle | 
|---|---|
| tf.add_n(inputs, name=None) | Somme pour chaque élément * Les entrées sont une liste de tenseurs, tous doivent avoir la même taille  | 
| tf.abs(x, name=None) | Valeur absolue pour chaque élément | 
| tf.neg(x, name=None) | Multipliez chaque élément par moins | 
| tf.sign(x, name=None) | 1 pour positif, 0 pour 0, négatif pour chaque élément-Multipliez la conversion par 1 | 
| tf.inv(x, name=None) | Nombre inverse pour chaque élément | 
| tf.square(x, name=None) | Prenez le carré pour chaque élément | 
| tf.round(x, name=None) | Arrondi par élément | 
| tf.sqrt(x, name=None) | Prenez racine pour chaque élément | 
| tf.rsqrt(x, name=None) | Prendre l'inverse de l'itinéraire pour chaque élément | 
| tf.pow(x, y, name=None) | Multiplicateur pour chaque élément(élément de x^élément de y) | 
| tf.exp(x, name=None) | Prend une fonction exponentielle avec un nombre naturel comme base pour chaque élément | 
| tf.log(x, name=None) | Prenez un logarithme naturel pour chaque élément | 
| tf.ceil(x, name=None) | Reportez-vous après la virgule décimale pour chaque élément | 
| tf.floor(x, name=None) | Tronquer chaque élément après la virgule décimale | 
| tf.maximum(x, y, name=None) | Prenez la valeur maximale pour chaque élément | 
| tf.minimum(x, y, name=None) | Prenez la valeur minimale pour chaque élément | 
| tf.cos(x, name=None) | Prenez cos pour chaque élément | 
| tf.sin(x, name=None) | Prenez le péché pour chaque élément | 
Dans l'exemple utilisant le carré, utilisez la formule suivante.
y=x2+b
Exemple d'utilisation) vim square_test.py
import tensorflow as tf
def x2_plus_b(x, b):
    _x = tf.constant(x)
    _b = tf.constant(b)
    result = tf.square(_x)
    result = tf.add(result, _b)
    return result
with tf.Session() as sess:
    result = sess.run([x2_plus_b(2.0,3.0)])
    print result
résultat
python square_test.py
[7.0]
Cliquez ici pour d'autres fonctions mathématiques (http://mirai-tec.hatenablog.com/entry/2016/02/22/001459) J'ai fait référence au blog.
vim basic_math_fun.py
import tensorflow as tf
sess = tf.InteractiveSession()
################
# tf.add_n
################
a = tf.constant([1., 2.])
b = tf.constant([3., 4.])
c = tf.constant([5., 6.])
tf_addn = tf.add_n([a, b, c])
print "tf.add_n"
print sess.run(tf_addn)
# output:
# tf.add_n
# [  9.  12.]
################
# tf.abs
################
x = tf.constant([[-1., 2.], [3., -4.]])
tf_abs = tf.abs(x)
print "tf.abs"
print sess.run(tf_abs)
# output:
# tf.abs
# [[ 1.  2.]
#  [ 3.  4.]]
################
# tf.neg
################
x = tf.constant([[-1., 2.], [3., -4.]])
tf_neg = tf.neg(x)
print "tf.neg"
print sess.run(tf_neg)
# output:
# tf.neg
# [[ 1. -2.]
#  [-3.  4.]]
################
# tf.sign
################
x = tf.constant([[-1., 2.], [3., -4.]])
tf_sign = tf.sign(x)
print "tf.sign"
print sess.run(tf_sign)
# output:
# tf.sign
# [[-1.  1.]
#  [ 1. -1.]]
################
# tf.inv
################
x = tf.constant([[-1., 2.], [3., -4.]])
tf_inv = tf.inv(x)
print "tf.inv"
print sess.run(tf_inv)
# output:
# tf.inv
# [[-1.          0.5       ]
#  [ 0.33333334 -0.25      ]]
################
# tf.square
################
x = tf.constant([[-1., 2.], [3., -4.]])
tf_square = tf.square(x)
print "tf.square"
print sess.run(tf_square)
# output:
# tf.square
# [[  1.   4.]
#  [  9.  16.]]
################
# tf.round
################
x = tf.constant([0.9, 2.5, 2.3, -4.4])
tf_round = tf.round(x)
print "tf.round"
print sess.run(tf_round)
# output:
# tf.round
# [ 1.  3.  2. -4.]
################
# tf.sqrt
################
x = tf.constant([[1., 2.], [3., 4.]])
tf_sqrt = tf.sqrt(x)
print "tf.sqrt"
print sess.run(tf_sqrt)
# output:
# tf.sqrt
# [[ 0.99999994  1.41421342]
#  [ 1.73205078  1.99999988]]
################
# tf.rsqrt
################
x = tf.constant([[1., 2.], [3., 4.]])
tf_rsqrt = tf.rsqrt(x)
print "tf.rsqrt"
print sess.run(tf_rsqrt)
# output:
# tf.rsqrt
# [[ 0.99999994  0.70710671]
# [ 0.57735026  0.49999997]]
################
# tf.pow
################
x = tf.constant([[2, 2], [3, 3]])
y = tf.constant([[8, 16], [2, 3]])
tf_pow = tf.pow(x, y)
print "tf.pow"
print sess.run(tf_pow)
# output:
# tf.pow
# [[  256 65536]
#  [    9    27]]
################
# tf.exp
################
x = tf.constant([[1., 2.], [3., 4.]])
tf_exp = tf.exp(x)
print "tf.exp"
print sess.run(tf_exp)
# output:
# tf.exp
# [[  2.71828175   7.38905621]
#  [ 20.08553696  54.59815216]]
################
# tf.log
################
x = tf.constant([[1., 2.], [3., 4.]])
tf_log = tf.log(x)
print "tf.log"
print sess.run(tf_log)
# output:
# tf.log
# [[ 0.          0.69314718]
#  [ 1.09861231  1.38629436]]
################
# tf.ceil
################
x = tf.constant([[1.1, 2.2], [3.3, 4.4]])
tf_ceil = tf.ceil(x)
print "tf.ceil"
print sess.run(tf_ceil)
# output:
# tf.ceil
# [[ 2.  3.]
#  [ 4.  5.]]
################
# tf.floor
################
x = tf.constant([[1.1, 2.2], [3.3, 4.4]])
tf_floor = tf.floor(x)
print "tf.floor"
print sess.run(tf_floor)
# output:
# tf.floor
# [[ 1.  2.]
#  [ 3.  4.]]
################
# tf.maximum
################
x = tf.constant([[2, 8], [3, 12]])
y = tf.constant([[4, 10], [1, 9]])
tf_maximum = tf.maximum(x, y)
print "tf.maximum"
print sess.run(tf_maximum)
# output:
# tf.maximum
# [[ 4 10]
#  [ 3 12]]
################
# tf.minimum
################
x = tf.constant([[2, 8], [3, 12]])
y = tf.constant([[4, 10], [1, 9]])
tf_minimum = tf.minimum(x, y)
print "tf.minimum"
print sess.run(tf_minimum)
# output:
# tf.minimum
# [[2 8]
#  [1 9]]
################
# tf.cos
################
x = tf.constant([[2., 8.], [3., 12.]])
tf_cos = tf.cos(x)
print "tf.cos"
print sess.run(tf_cos)
# output:
# tf.cos
# [[-0.41614681 -0.14550003]
#  [-0.9899925   0.84385395]]
################
# tf.sin
################
x = tf.constant([[2., 8.], [3., 12.]])
tf_sin = tf.sin(x)
print "tf.sin"
print sess.run(tf_sin)
# output:
# tf.sin
# [[ 0.90929741  0.98935825]
#  [ 0.14112    -0.53657293]]
sess.close()
référence: https://www.tensorflow.org/versions/r0.9/api_docs/python/math_ops.html http://dev.classmethod.jp/machine-learning/tensorflow-math/ http://mirai-tec.hatenablog.com/entry/2016/02/22/001459