Skip to content
Related Articles

Related Articles

Improve Article
Python – tensorflow.IndexedSlices.shape Attribute
  • Last Updated : 28 Jul, 2020

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

shape is used to get the tensorflow.TensorShape representing the shape of the dense tensor.

Syntax:  tensorflow.IndexedSlices.shape

Returns:  It returns tensorflow.TensorShape representing the shape of the dense tensor.

Example 1:



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], tf.constant([1, 2]))
  
# Finding Shape
shape = res.shape
  
# Printing the result
print('Shape: ', shape)

Output:


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

Example 2:

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], tf.constant([1]))
  
# Finding Shape
shape = res.shape
  
# Printing the result
print('Shape: ', shape)

Output:


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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :