神经网络学习2--Tensorflow 基本概念

使用图(graphs)来表示计算任务
在被称为会话(Session)的上下文(context)中执行图
使用Tensor表示数据
通过变量(Variable)维护状态
使用feed和fetch可以为任意的操作赋值或者从其中获取数据。

Tensorflow是一个编程系统,使用图(graphs)来表示计算任务,图(graphs)中的节点称之为op(operation),一个op获得0个或者多个Tensor,执行计算,产生0个或多个Tensor。
Tensor看作是一个n维的数组或列表。图必须在会话(session)里面启动。
这里写图片描述

>>> import tensorflow as tf 
>>> m1 = tf.constant([[3,3]])
>>> m2 = tf.constant([[2],[3]])
>>> product = tf.matmul(m1,m2)
>>> print(product)
Tensor("MatMul:0", shape=(1, 1), dtype=int32) 

>>> sess = tf.Session()
>>> result=sess.run(product)
>>> print(result)
[[15]] 

张量有多种. 零阶张量为 纯量或标量 (scalar) 也就是一个数值. 比如 [1]
一阶张量为 向量 (vector), 比如 一维的 [1, 2, 3]
二阶张量为 矩阵 (matrix), 比如 二维的 [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
以此类推, 还有 三阶 三维的 …

猜你喜欢

转载自blog.csdn.net/qq_16481211/article/details/80969068
今日推荐