- TensorFlow 2.0 Quick Start Guide
- Tony Holdroyd
- 65字
- 2021-06-24 16:02:04
Casting a tensor to another (tensor) datatype
TensorFlow variables of one type may be cast (coerced) to another type. More details may be found at https://www.tensorflow.org/api_docs/python/tf/cast.
Take the following example:
i = tf.cast(t1, dtype=tf.int32) # 42
i
The output will be as follows:
<tf.Tensor: id=116, shape=(), dtype=int32, numpy=42>
With truncation, it would be as follows:
j = tf.cast(tf.constant(4.9), dtype=tf.int32) # 4
j
The output will be as follows:
<tf.Tensor: id=119, shape=(), dtype=int32, numpy=4>
推薦閱讀
- 輕松學C語言
- Dreamweaver CS3+Flash CS3+Fireworks CS3創意網站構建實例詳解
- 高性能混合信號ARM:ADuC7xxx原理與應用開發
- Natural Language Processing Fundamentals
- Cloud Analytics with Microsoft Azure
- 完全掌握AutoCAD 2008中文版:綜合篇
- 大數據技術與應用
- 愛犯錯的智能體
- 單片機技術一學就會
- PostgreSQL 10 Administration Cookbook
- Mastering ServiceNow Scripting
- 人工智能云平臺:原理、設計與應用
- 菜鳥起飛五筆打字高手
- 電機與電力拖動
- Mastering Android Game Development with Unity