Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get data type of a tensor in tensorflow?

Which function is used to get the data type of tensors in tensorflow in python? I need to define dynamic data types according to different tensors.

like image 437
yusuf Avatar asked May 15 '17 11:05

yusuf


People also ask

How do you find the datatype of a tensor?

We can access the data type of a tensor using the ". dtype" attribute of the tensor. It returns the data type of the tensor.

Where can I find TensorFlow Dtype of tensor?

You can use get_shape() to get the shape of a tensorflow variable. You can use dtype property to get the type of a tensorflow variable. You can use as_numpy_dtype property of dtype to convert from tf. dtype to numpy dtype.

What is tensor data type?

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.


1 Answers

You can get the type using x.dtype, as follows:

import tensorflow as tf
x=tf.constant([1,2])
x.dtype

This prints tf.int32

like image 188
Miriam Farber Avatar answered Sep 21 '22 22:09

Miriam Farber