random.uniform()详解
•
人工智能
一、函数介绍
函数原型: numpy.random.uniform(low,high,size)
功能:从一个均匀分布[low,high)中随机采样,注意定义域是左闭右开,即包含low,不包含high.
random.uniform(shape,
minval=0,
maxval=None,
dtype=dtypes.float32,
seed=None,
name=None)
参数解释:
- shape: 张量形状
- minval: 随机值范围下限,默认0
- maxval: 随机值范围上限(若薇浮点数,则默认为1)
- dtype: 输出的类型:float16、float32、float64、int32、orint64
- seed: 整数作为随机数种子
- name: 操作的名称(可选)
二、举例
代码:
# -------创建词汇查找表--------- vocab = ["<1H OCEAN", "INLAND", "NEAR OCEAN", "NEAR BAY", "ISLAND"] indices = tf.range(len(vocab),dtype=tf.int64) # 创建索引张量 table_init = tf.lookup.KeyValueTensorInitializer(vocab, indices) # 查找表初始化程序 num_oov_buckets = 2 # 词汇表外的捅的大小(分配给未知单词,如果太小则会出现重复) table = tf.lookup.StaticVocabularyTable(table_init, num_oov_buckets) # 创建查找表 embedding_dim = 2 embed_init = tf.random.uniform([len(vocab) + num_oov_buckets, embedding_dim]) # 生成7*2的张量 embedding_matrix = tf.Variable(embed_init) print(embedding_matrix)
输出:
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/677693f77b.html
