TensorFlow基礎知識

2021-10-08 08:47:59 字數 1206 閱讀 3044

從helloword開始

mkdir  mooc # 新建乙個mooc資料夾

cd mooc

mkdir 1.helloworld # 新建乙個helloworld資料夾

cd 1.helloworld

touch helloworld.py

**

# -*- coding: utf-8 -*-

# 引入 tensorflow 庫

import tensorflow as tf

# 建立乙個 constant(常量)operation(操作)

hw = tf.constant("hello world! i love tensorflow!") # 我愛 tensorflow

# 啟動乙個 tensorflow 的 session(會話)

sess = tf.session()

# 執行 graph(計算圖)

print(sess.run(hw))

# 關閉 session(會話)

sess.close()

python常用庫numpy

tensorflow和numpy有一定聯絡

介紹tensor時,有很多api名稱很相似

numpy官網,科學計算。n階陣列物件。

numpy速度是非常快的,比原生快很多。

因為numpy的許多函式是用c語言來實現的。還使用了一些優化,甚至比你自己用c實現快很多。

import numpy as np

vector = np.array([1,2,3])

vector.shape

vector.size

vector.ndim

type(vector)# 建立二維陣列(矩陣)matrix = np.array([[1, 2],[3, 4]])

matrix.shape

matrix.size

matrix.ndim

type(matrix)

對於矩陣進行轉置全0

one = np.arange(12)

two = one.reshape((3,4))

two.shape

two.size

two.ndim

tensorflow 基礎知識

變數不執行,只列印行列引數,sess.run a 列印出變數實際內容 y int x0 x1 1 for x0,x1 in x 這樣能夠判斷x生成的資料兩個數的和小於1,那麼y就是1,否則是0 rng np.random.randomstate seed x rng.rand 32,2 生成32行2...

TensorFlow基礎知識

title tensorflow基礎知識 date 2018 03 31 14 13 12 categories tensorflow是乙個採用資料流圖 data flow graphs 用於數值計算的開源軟體庫。下圖就是乙個資料流圖。資料流圖是乙個用來描述數學計算的由 結點 nodes 和 線 e...

TensorFlow基礎知識彙總

一 constant 常量 constant是tensorflow的常量節點,通過constant方法建立,其是計算圖 computational graph 中的起始節點,是傳入資料。建立方式 cons tf.constant value 1,2 dtype tf.float32,shape 1,...