我正在尝试进行逻辑回归,我的训练数据集来自一个 numpy float64 数组。我的代码看起来像,
import tensorflow as tf
graph = tf.Graph()
with graph.as_default():
examples =tf.constant(mat6) # mat6 is a numpy float64 array
t_labels = tf.constant(labels) # labels is an a numpy float64 array
W = tf.Variable(tf.truncated_normal([115713, 2]))
b = tf.Variable(tf.zeros([2]))
logits = tf.matmul(examples, W)+b
这会引发异常
TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type float64 of argument 'a'.
这可能是因为 W 和 b 是 float32 而不是 float64。有没有办法转换 W 和 b 或将其创建为 float64
最佳答案
要实现此功能,您应该使用 tf.float64
初始值定义 W
和 b
变量。 tf.truncated_normal()
和 tf.zeros()
每个操作都有一个可选的 dtype
参数,可以将其设置为 tf.float64
,如下所示:
W = tf.Variable(tf.truncated_normal([115713, 2], dtype=tf.float64))
b = tf.Variable(tf.zeros([2], dtype=tf.float64))
关于python - 在 tensorflow 中创建一个 float64 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35884045/