API function TensorFlow-- common tensor operations

1. tensor

Tensor can be said to mark TensorFlow, because the name of the entire framework TensorFlow is meant tensor current, comprehensive understanding of what tensor. In TensorFlow tensor program uses data structure to represent all of the data in the computation graph, between the operating data are Tensor, Tensor can be seen as the n-dimensional array or list, each tensor contains the type (type), order ( rank), and shape (shape).

2.tensor type

Type tensor are mainly as follows:

tf.float32: 32-bit floating point 
tf.float64: 64-bit floating point
tf.int64: 64-bit signed integer
tf.int32: 32-bit signed integer
tf.int16: 16-bit signed integer
tf. int8: 8-bit signed integer
tf.uint8: 8-bit unsigned integer 
tf.string: variable length byte array
tf.bool: Boolean
tf.complex64: a plurality of two 32-bit floating-point consisting of: real and imaginary portions

rank (rank)

rank (order) refers to the dimension, which can be observed by the parentheses the number of layers, such as tensor [[1,2,3], [2,3,4], [3,4,5]] of the order of 2 order, scalar, vector, matrix 0,1,2 respectively.

shape (shape)

used to describe the shape of the internal organizational relationship tensor, the shape usually be a list of integers or tuples that can also be used in the correlation TensorFlow shape function to represent.

Tensor related operations

Tensor related operations including the type of operation, the digital operation, shape conversion, data manipulation

Type of operation

IF  __name__ == ' __main__ ' : 
    with tf.Session () AS sess: 
        Print (sess.run (tf.string_to_number ( ' 123.456 ' )))   # characters into digital 
        Print (sess.run (tf.to_double (3 )))         # turn floating- 
        Print (sess.run (tf.to_int32 (3.1415)))     # turn integer 
        Print (sess.run (tf.cast (3.1415, tf.int32)))   # the type of transfer specified type

 

Import tensorflow TF AS 

IF  the __name__ == ' __main__ ' : 
    with tf.Session () AS Sess: 
        Print (sess.run (tf.ones ([2,. 3], DTYPE = tf.float32)))   # generate a full 1 data 
        Print (sess.run (tf.zeros ([2,. 3], DTYPE = tf.float32)))    # generates data of all 0 
        Print (sess.run (tf.ones_like ([. 1, 2,. 3,. 4] )))     # generate a predetermined shape of the whole data 
        Print (sess.run (tf.zeros_like ([2,. 3,. 4,. 5])))   # generated all-0 data of a predetermined shape 
        Print (sess.run (tf.fill ([2, 2], 6)))   # specified value fill shapes 
        Print (sess.run (tf.constant ((2,. 3),. 3)))   # generates constant
        print (sess.run (tf.random_normal ([3, 3], mean = 2.5, stddev = 1.0, dtype = tf.float32,)))

 

 Too much. . . .

 

Guess you like

Origin www.cnblogs.com/baby-lily/p/10931819.html