tensorflow基础

  1. tf. constant, 定义tensor(张量)
a = tf.constant([[1,2], [3, 4]])
print(a)

tf.Tensor(
[[1 2]
 [3 4]], shape=(2, 2), dtype=int32)
  1. tf.add, 两个张量相加
a = tf.constant([[1, 2], [3, 4]])
b = tf.constant([[5, 6], [7, 8]])
print(tf.add(a, b))
print(a+b) //似乎和tf.add功能完全相同

tf.Tensor(
[[ 6  8]
 [10 12]], shape=(2, 2), dtype=int32)
tf.Tensor(
[[ 6  8]
 [10 12]], shape=(2, 2), dtype=int32)
  1. tf.matmul 矩阵乘法
a = tf.constant([[1, 2], [3, 4]])
b = tf.constant([[5, 6], [7, 8]])
print(tf.add(a, b))
print(a+b)

print(tf.matmul(a, b))
print(a*b)

tf.Tensor(
[[ 6  8]
 [10 12]], shape=(2, 2), dtype=int32)
tf.Tensor(
[[ 6  8]
 [10 12]], shape=(2, 2), dtype=int32)
tf.Tensor(
[[19 22]
 [43 50]], shape=(2, 2), dtype=int32)
tf.Tensor(
[[ 5 12]
 [21 32]], shape=(2, 2), dtype=int32)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • TF API数学计算tf...... :math(1)刚开始先给一个运行实例。tf是基于图(Graph)的计算系统...
    MachineLP阅读 3,578评论 0 1
  • tensorflow开发API 架构 Modules app module: Generic entry poin...
    sennchi阅读 1,386评论 0 2
  • 姓名:顾林林 公司:上海陈工电控科技有限公司 【411期】反省一组 学员 日精进打卡第320天 【447期】乐观一...
    紫魇阅读 93评论 0 0
  • 小小精灵不起眼, 春夏难得半日闲。 一点一滴行万次, 酿得蜜香为谁甜。 曰月复转家难安, 骠肥黄蜂常来犯。 舍身就...
    山上丑石阅读 367评论 0 0
  • 最近几年的年味就是没味,每每过年都是无法与家人相聚,坚守于工作岗位,感受着整天街道关门的冷冷清清,孤独的、呆傻的坐...
    平凡女汉子阅读 314评论 0 3