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?
We can access the data type of a tensor using the ". dtype" attribute of the tensor. It returns the data type of the tensor.
Tensors are multi-dimensional arrays with a uniform type (called a dtype ). You can see all supported dtypes with names(tf$dtypes) . If you're familiar with R array or NumPy, tensors are (kind of) like R or NumPy arrays. All tensors are immutable: you can never update the contents of a tensor, only create a new one.
To get the shape of a tensor as a list in PyTorch, we can use two approaches. One using the size() method and another by using the shape attribute of a tensor in PyTorch.
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'>
To get the type you can do
x.dtype
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With