Skip to content
Related Articles

Related Articles

Python – tensorflow.IndexedSlices.op Attribute

View Discussion
Improve Article
Save Article
  • Last Updated : 28 Jul, 2020

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks.

op is used to find the operation used to that produces value as an output. It only works when eager execution is disabled.

Syntax: tensorflow.IndexedSlices.op

Returns: It returns the operation that produces values as an output.

Example 1: In this example eager execution is disabled.

Python3




# Importing the library
import tensorflow as tf
  
# Disable Eager execution
tf.compat.v1.disable_eager_execution()
  
# Initializing the input
data = tf.constant([[1, 2, 3], [4, 5, 6]])
  
# Printing the input
print('data: ', data)
  
# Calculating result
res = tf.IndexedSlices(data, [0], 1)
  
# Finding operation
op = res.op
  
# Printing the result
print('Operation: ', op)


Output:


data:  Tensor("Const:0", shape=(2, 3), dtype=int32)
Operation:  name: "Const"
op: "Const"
attr {
  key: "dtype"
  value {
    type: DT_INT32
  }
}
attr {
  key: "value"
  value {
    tensor {
      dtype: DT_INT32
      tensor_shape {
        dim {
          size: 2
        }
        dim {
          size: 3
        }
      }
      tensor_content: "\001\000\000\000\002\000\000\000\003\000\000\000\004\000\000\000\005\000\000\000\006\000\000\000"
    }
  }
}

Example 2: In this example eager execution is enable so it will raise AttributeError.

Python3




# Importing the library
import tensorflow as tf
  
# Initializing the input
data = tf.constant([[1, 2, 3], [4, 5, 6]])
  
# Printing the input
print('data: ', data)
  
# Calculating result
res = tf.IndexedSlices(data, [0], 1)
  
# Finding operation
op = res.op
  
# Printing the result
print('Operation: ', op)


Output:


data:  tf.Tensor(
[[1 2 3]
 [4 5 6]], shape=(2, 3), dtype=int32)

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-1-8dd32836815c> in <module>()
     12 
     13 # Finding operation
---> 14 op = res.op
     15 
     16 # Printing the result

1 frames

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in op(self)
   1111   def op(self):
   1112     raise AttributeError(
-> 1113         "Tensor.op is meaningless when eager execution is enabled.")
   1114 
   1115   @property

AttributeError: Tensor.op is meaningless when eager execution is enabled.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!