1.tf.where()
import tensorflow as tf 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)
输出结果:
2.np.random.RandomState.rand()
import numpy as np rdm = np.random.RandomState(seed=1) # seed=常数,每次生成随机数相同 a = rdm.rand() # 返回一个随机标量 b = rdm.rand(2, 3) # 返回维度为2行3列的随机数矩阵 print('a:', a) print('b:', b)
输出结果:
3.np.vstack()
import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) c = np.vstack((a, b)) print('c: ', c)
4.
mgrid[]返回若干组维度相同的数组
x.ravel(), y.ravel()分别将x,y拉直成一维的
import numpy as np x, y = np.mgrid[1:3:1, 2:4:0.5] grid = np.c_[x.ravel(), y.ravel()] print("x:", x) print("y:", y) print("grid: ", grid)