Python – tensorflow.identity_n()
Last Updated :
20 Jul, 2020
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks.
identity_n() is used get a list of Tensor with same shape and content as input Tensor.
Syntax: tensorflow.identity_n( input, name)
Parameters:
- input: It is a Tensor.
- name(optional): It defines the name for the operation.
Returns: It returns a list of Tensors with same shape and content as input.
Example 1:
Python3
import tensorflow as tf
data = tf.constant([[ 1 , 2 , 3 ], [ 3 , 4 , 5 ], [ 5 , 6 , 7 ]])
print ( 'data: ' , data)
res = tf.identity_n(data)
print ( 'res: ' , res)
|
Output:
data: tf.Tensor(
[[1 2 3]
[3 4 5]
[5 6 7]], shape=(3, 3), dtype=int32)
res: [<tf.Tensor: shape=(3, ), dtype=int32, numpy=array([1, 2, 3], dtype=int32)>,
<tf.Tensor: shape=(3, ), dtype=int32, numpy=array([3, 4, 5], dtype=int32)>,
<tf.Tensor: shape=(3, ), dtype=int32, numpy=array([5, 6, 7], dtype=int32)>]
Example 2:
Python3
import tensorflow as tf
data = tf.constant([ 1 , 2 , 3 ])
print ( 'data: ' , data)
res = tf.identity_n(data)
print ( 'res: ' , res)
|
Output:
data: tf.Tensor([1 2 3], shape=(3, ), dtype=int32)
res: [<tf.Tensor: shape=(), dtype=int32, numpy=1>,
<tf.Tensor: shape=(), dtype=int32, numpy=2>,
<tf.Tensor: shape=(), dtype=int32, numpy=3>]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...