Python‎ > ‎

tensorflow

http://www.adilwaseem.com/

 The tensorflow run the String.
import tensorflow as tf
c = tf.constant('Python Lake')

Tensor("Const:0", shape=(), dtype=string) 


 The tensorflow returns with the dtype.
 import tensorflow 

graph = tensorflow.Graph()


with graph.as_default():
  x = tensorflow.constant(12, name="x_const")
  y = tensorflow.constant(20, name="y_const")
  x_y_sum= tensorflow.add(x, y, name="x_y_sum")

  with tensorflow.Session() as v:
      print(x_y_sum.dtype)

 <dtype: 'int32'>



 The tensorflow round the array of constant values.
import tensorflow as tf

x = tf.constant([0.9, 2.5, 2.3, 1.5, -4.5])

r=tf.round(x)  # [ 1.0, 2.0, 2.0, 2.0, -4.0 ]

print(r)
 Tensor("Const:0", shape=(5,), dtype=float32)
Tensor("Round:0", shape=(5,), dtype=float32)



The colums and rows are defined in tensorflow.constant()
import tensorflow as tf

tensor = tf.constant(-1.5, shape=[5, 3])

with tf.Session() as session:
    result=session.run(tensor)
    print(result)

 
[[-1.5 -1.5 -1.5]
 [-1.5 -1.5 -1.5]
 [-1.5 -1.5 -1.5]
 [-1.5 -1.5 -1.5]
 [-1.5 -1.5 -1.5]]
>>>



 The tensor value is divided by 2 and first row is printed. 
 
import tensorflow as tf
tensor = tf.constant(-1.5, shape=[5, 3])

with tf.Session() as session:
    result=session.run(tensor[1]/2)
    print(result)

 
[-0.75 -0.75 -0.75]



 The tf.equal method is used to equate the tensor values.
 import tensorflow as tf
tensor1 = tf.constant(-1.5, shape=[5, 3])
tensor2 = tf.constant(-1.5, shape=[5, 3])
equal=tf.equal(tensor1,tensor2)

with tf.Session() as session:
    result=session.run(equal)
    print(result)

 
[[ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]]

Subpages (25): View All
Comments