tf.where()&np.random.RandomState.rand()&np.vstack&np.mgrid .ravel np.c_[]

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:\n', 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:\n", grid)

 

posted @ 2020-08-26 20:22  GumpYan  阅读(149)  评论(0编辑  收藏  举报