Tensorflow - tf commonly used functions using the (Update)

I am more lazy, intermittently update the common function tf for reference: 

 

一、tf.reduce_sum( )

reduce_sum () is a personal understanding summation function dimensionality reduction, in which tensorflow, Tensor are calculated, the summation may be controlled by adjusting the dimension of the axis dimension.

parameter:

  • input_tensor:. To reduce the amount of digital photos should have a type.
  • axis:. If you want to reduce the size of None (default), all of the reduced size must be in the range [-rank (input_tensor), rank (input_tensor)) inside.
  • keep_dims: If true, the reserved length is reduced in size to 1.
  • name: name of the operation (optional).
  • reduction_indices: the name of the axis of the abandoned.

return:

This function returns reduce the amount of copies.

numpy compatibility

Equivalent np.sum;

 

Here is the order tensor axis using the function specified in order to eliminate tensor axis, while all of the lower order elements cumulatively summing operation.

A look at the official example:

x = tf.constant([[1, 1, 1], [1, 1, 1]])
tf.reduce_sum(x)  # 6
tf.reduce_sum(x, 0)  # [2, 2, 2]
tf.reduce_sum(x, 1)  # [3, 3]
tf.reduce_sum(x, 1, keep_dims=True)  # [[3], [3]]
tf.reduce_sum(x, [0, 1])  # 6

This function calculates the sum of each dimension element of a tensor. 

Input_tensor function in accordance with a given axis has reduced dimensions; unless keep_dims is true, otherwise it will decrease the rank tensor in an axis of each entry; keep_dims If true, the reduced dimension will remain length 1. 

If there is no entry axis, all dimensions are reduced, and returns a single element having a tensor.

 

 二、tf.ones_like | tf.zeros_like

tf.ones_like (tensor, dype = None, name = None)
tf.zeros_like (tensor, dype = None, name = None)
Create a consistent with the given tensor tensor type size, all of whose elements are 0 and 1, the exemplary as follows:

tensor=[[1, 2, 3], [4, 5, 6]] 
x = tf.ones_like(tensor) 
print(sess.run(x))

#[[1 1 1],
# [1 1 1]]

 

Guess you like

Origin www.cnblogs.com/Jesee/p/11455697.html