CGTheLegend
CGTheLegend

Reputation: 774

How to get the type of a Tensor?

I'm looking for something similar to the effects of:

x.get_shape()

that will give the type of x. Is there is any function for this?

Upvotes: 25

Views: 65607

Answers (2)

umutto
umutto

Reputation: 7690

You can use get_shape() to get the shape of a tensorflow variable.

>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.get_shape()
(256, 100)

You can use dtype property to get the type of a tensorflow variable.

>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.dtype
<dtype: 'float32_ref'>

You can use as_numpy_dtype property of dtype to convert from tf.dtype to numpy dtype.

>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.dtype.as_numpy_dtype
<class 'numpy.float32'>

Upvotes: 42

Miriam Farber
Miriam Farber

Reputation: 19634

To get the type you can do

x.dtype

Upvotes: 16

Related Questions