- TensorFlow Machine Learning Cookbook
- Nick McClure
- 194字
- 2021-04-02 20:36:30
Operations in a Computational Graph
Now that we can put objects into our computational graph, we will introduce operations that act on such objects.
Getting ready
To start a graph, we load TensorFlow and create a session, as follows:
import tensorflow as tf sess = tf.Session()
How to do it…
In this example, we will combine what we have learned and feed in each number in a list to an operation in a graph and print the output:
- First we declare our tensors and placeholders. Here we will create a
numpy
array to feed into our operation:import numpy as np x_vals = np.array([1., 3., 5., 7., 9.]) x_data = tf.placeholder(tf.float32) m_const = tf.constant(3.) my_product = tf.mul(x_data, m_const) for x_val in x_vals: print(sess.run(my_product, feed_dict={x_data: x_val})) 3.0 9.0 15.0 21.0 27.0
How it works…
Steps 1 and 2 create the data and operations on the computational graph. Then, in step 3, we feed the data through the graph and print the output. Here is what the computational graph looks like:

Figure 1: Here we can see in the graph that the placeholder, x_data
, along with our multiplicative constant, feeds into the multiplication operation.
推薦閱讀
- 常用元器件的識別與檢測
- 玩轉(zhuǎn)我的iPhone 4
- 新手學(xué)修手機(jī)
- 2018—2019年中國無線電應(yīng)用與管理藍(lán)皮書
- 想到做到:Android開發(fā)關(guān)鍵技術(shù)與精彩案例
- 手機(jī)故障維修技巧與實(shí)例
- iOS開發(fā)快速進(jìn)階與實(shí)戰(zhàn)
- WCDMA網(wǎng)絡(luò)測試與優(yōu)化教程
- 電力通信、信息原理與技術(shù) 上冊:電力通信
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)
- 輕松玩轉(zhuǎn)DSP:基于TMS320F2833x
- 從1G到5G:移動通信如何改變世界
- 嚴(yán)肅的密碼學(xué):實(shí)用現(xiàn)代加密術(shù)
- Cadence Allegro SPB 16.3常用功能與應(yīng)用實(shí)例精講
- 常用器件及控制線路學(xué)與用