常用函数2
import tensorflow as tf
import numpy as np
"""tf.where(),条件语句,真返回a"""
a = tf.constant([1, 2, 3, 1, 1])
b = tf.constant([0, 1, 3, 4, 5])
c = tf.where(tf.greater(a, b), a, b) # 若a>b,返回a对应位置的元素,否则返回b对应位置的元素
print("c:", c)
"""np.random.RandomState() 返回[0,1)间的随机数"""
rdm = np.random.RandomState(seed=1) #seed=常数每次生成随机数相同
print("rdm=",rdm)
a = rdm.rand() #返回随机标量
b = rdm.rand(2, 3) #2行3列随机矩阵
print("a:", a)
print("b:", b)
"""np.vstack() 将两个数组按垂直方向叠加"""
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.vstack((a, b))
print("c:\n", c)
"""np.mgrid[] 返回若干组维度相同的等差数组 [起始值,结束值)
x.ravel 将x变为一维数组,相当于把x拉直
np.c_[]使返回的间隔数值点配对"""
生成等间隔数值点
x, y = np.mgrid[1:3:1, 2:4:0.5]
将x, y拉直,并合并配对为二维张量,生成二维坐标点
grid = np.c_[x.ravel(), y.ravel()]
print("x:\n", x)
print("y:\n", y)
print("x.ravel():\n", x.ravel())
print("y.ravel():\n", y.ravel())
print('grid:\n', grid)