Untitled
python
2 months ago
1.0 kB
2
Indexable
Never
import tensorflow as tf # print(tf.__version__) # scalar value: 4, 2.5, -8 # vector: [3, 4, 2, 1] # matrix: [[1, 3, 2] # [3, 5, 1]] # tensor: color image[height, width, color] = [1024, 768, 3], video[height, width, color, time], text (document = {sentences}, sentence = {words}, word = {characters}) # 2x2 matrix # print(tf.constant(2, shape=(2, 4), dtype=tf.int16)) # identity matrix # print(tf.eye(5)) # create a matrix filled with ones # print(tf.ones(shape=(3, 2, 4))) # create a matrix filled with zeros # print(tf.zeros(shape=(3, 2, 4))) # randomly create a matrix using normal distribution mean=0, stddev=1 # print(tf.random.normal(shape=(2, 3), mean=0, stddev=1)) # basic math # a = tf.constant([1, 2, -4]) # b = tf.constant([4, 3, 1]) # element-wise operators # print(a + b) # print(a - b) # print(a * b) # print(a / b) # print(a % b) # print(a**3) # matmul (matrix multiplication) a = tf.constant([[1, 2, 3], [4, 1, 0]]) b = tf.constant([[1], [0], [2]]) print(a) print(b) print(tf.matmul(a, b))