用法
__bool__()
拋出
-
TypeError
。
防止張量被用作 Python bool
的虛擬方法。
當用戶在 AutoGraph 未轉換的代碼中無意中將 Tensor
視為布爾值(最常見於 if
或 while
語句中)時,此重載會引發 TypeError
。例如:
if tf.constant(True): # Will raise.
# ...
if tf.constant(5) < tf.constant(7): # Will raise.
# ...
相關用法
- Python tf.Tensor.__rsub__用法及代碼示例
- Python tf.Tensor.__lt__用法及代碼示例
- Python tf.Tensor.__abs__用法及代碼示例
- Python tf.Tensor.__getitem__用法及代碼示例
- Python tf.Tensor.__ge__用法及代碼示例
- Python tf.Tensor.__rmatmul__用法及代碼示例
- Python tf.Tensor.__xor__用法及代碼示例
- Python tf.Tensor.__sub__用法及代碼示例
- Python tf.Tensor.__rpow__用法及代碼示例
- Python tf.Tensor.__gt__用法及代碼示例
- Python tf.Tensor.__le__用法及代碼示例
- Python tf.Tensor.__pow__用法及代碼示例
- Python tf.Tensor.__matmul__用法及代碼示例
- Python tf.Tensor.set_shape用法及代碼示例
- Python tf.Tensor.ref用法及代碼示例
- Python tf.Tensor.get_shape用法及代碼示例
- Python tf.TensorSpec.from_spec用法及代碼示例
- Python tf.Tensor用法及代碼示例
- Python tf.TensorSpec.from_tensor用法及代碼示例
- Python tf.TensorShape.merge_with用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.Tensor.__bool__。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。