版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/z_feng12489/article/details/89245641
Pytorch 中的布尔类型
pytorch 中没有对布尔类型的支持。用 0 & 1 来表示。
import torch
a = torch.tensor(1.)
b = torch.tensor(1.)
a == b # tensor(1, dtype=torch.uint8)
a != b # tensor(0, dtype=torch.uint8)
Pytorch 中的 str 类型
Pytorch 没有对 str 类型的支持。只能通过编码的方式进行,例如 one-hot。
tensorflow 中的布尔类型
tensorflow 中有对布尔类型的支持。
import tensorflow as tf
a = tf.constant(1.)
b = tf.constant(1.)
tf.equal(a, b) # <tf.Tensor: id=806, shape=(), dtype=bool, numpy=True>
tf.not_equal(a, b) # <tf.Tensor: id=837, shape=(), dtype=bool, numpy=False>
tensorflow 中的 str 类型
tensorflow 中有对 str 类型的支持。
import tensorflow as tf
str_ = tf.constant('Hello world!')
str_ # <tf.Tensor: id=305, shape=(), dtype=string, numpy=b'hello world!'>