Presentation is loading. Please wait.

Presentation is loading. Please wait.

雲端計算.

Similar presentations


Presentation on theme: "雲端計算."— Presentation transcript:

1 雲端計算

2 Tensorflow Python3.5 while

3 Tensorflow

4 tensorflow結構

5 hello world from __future__ import print_function
import tensorflow as tf try: tf.contrib.eager.enable_eager_execution() except ValueError: pass # enable_eager_execution errors after its first call tensor = tf.constant('Hello, world!') tensor_value = tensor.numpy() print(tensor_value)

6 tensors 張量 任意維度的陣列 scalar純量: 0-d array vector向量: 1-d array
‘hello’ or 5 vector向量: 1-d array [2, 3, 5, 7, 11] or [5] matrix矩陣: 2-d array [[3.1, 8.2, 5.9][4.3, -2.7, 6.5]]

7 constant import tensorflow as tf x = tf.constant(5.2)
y = tf.Variable([5]) y = tf.Variable([0]) y = y.assign([5]) with tf.Session() as sess: print(x.eval())

8 tf.add() from __future__ import print_function import tensorflow as tf
g = tf.Graph() with g.as_default(): x = tf.constant(8, name="x_const") y = tf.constant(5, name="y_const") my_sum = tf.add(x, y, name="x_y_sum") with tf.Session() as sess: print(my_sum.eval())

9 Define a third scalar integer constant, z, and assign it a value of 4
Define a third scalar integer constant, z, and assign it a value of 4. Add z to my_sum to yield a new sum. Solution: import tensorflow as tf g = tf.Graph() with g.as_default(): x = tf.constant(8, name="x_const") y = tf.constant(5, name="y_const") my_sum = tf.add(x, y, name="x_y_sum") z = tf.constant(4, name="z_const") new_sum = tf.add(my_sum, z, name="x_y_z_sum") with tf.Session() as sess: print(new_sum.eval())

10 Vector Addition 向量加法 import tensorflow as tf
with tf.Session() as sess: primes = tf.constant([2, 3, 5, 7, 11, 13], dtype=tf.int32) print("primes:", primes.eval()) ones = tf.ones([6], dtype=tf.int32) print("ones:", ones.eval()) just_beyond_primes = tf.add(primes, ones) print("just_beyond_primes:", just_beyond_primes.eval()) twos = tf.constant([2, 2, 2, 2, 2, 2], dtype=tf.int32) primes_doubled = primes * twos print("primes_doubled:", primes_doubled.eval())

11 shape import tensorflow as tf with tf.Session() as sess:
# A scalar (0-D tensor). scalar = tf.zeros([]) # A vector with 3 elements. vector = tf.zeros([3]) # A matrix with 2 rows and 3 columns. matrix = tf.zeros([2, 3]) print('scalar has shape', scalar.get_shape(), 'and value:\n', scalar.eval()) print('vector has shape', vector.get_shape(), 'and value:\n', vector.eval()) print('matrix has shape', matrix.get_shape(), 'and value:\n', matrix.eval())

12 matrix multiplication 矩陣乘法
import tensorflow as tf with tf.Session() as sess: # A 3x4 matrix (2-d tensor). x = tf.constant([[5, 2, 4, 3], [5, 1, 6, -2], [-1, 3, -1, -2]], dtype=tf.int32) # A 4x2 matrix (2-d tensor). y = tf.constant([[2, 2], [3, 5], [4, 5], [1, 6]], dtype=tf.int32) # Multiply `x` by `y`; result is 3x2 matrix. matrix_multiply_result = tf.matmul(x, y) print(‘3x4 matrix:’) print(x.eval()) print(‘4x2 matrix:’) print(y.eval()) print(matrix_multiply_result.eval())

13 reshaping import tensorflow as tf matrix = tf.constant(
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16]], dtype=tf.int32) reshaped_2x8_matrix = tf.reshape(matrix, [2, 8]) reshaped_4x4_matrix = tf.reshape(matrix, [4, 4]) print("Original matrix (8x2):") print(matrix.eval()) print("Reshaped matrix (2x8):") print(reshaped_2x8_matrix.eval()) print("Reshaped matrix (4x4):") print(reshaped_4x4_matrix.eval())

14 驗收 a = tf.constant([5, 3, 2, 7, 1, 4]) b = tf.constant([4, 6, 3])

15 Python3.5 while

16 del remove()

17 pop()

18 sorted() 回傳一個排序好新的list,可用來排序任何的string, list, dictionary, tuple...
預設: 從小排到大 參數 reverse=True :從大排到小

19 串列的串列 不換行

20 while

21 while…else…

22 break

23 continue

24 random

25 驗收 Create 20 random value in a list *use pop()

26 驗收 Create 20 random value in a list *use pop()


Download ppt "雲端計算."

Similar presentations


Ads by Google