【发布时间】:2016-07-22 13:26:22
【问题描述】:
我有大量标签,我通过以下方式制作独一无二的标签:
unique_train_labels = set(train_property_labels)
打印为set([u'A', u'B', u'C'])。我想使用名为“no_region”的新标签创建一组新的唯一标签,并且正在使用:
unique_train_labels_threshold = unique_train_labels.add('no_region')
但是,这打印出来是None。
我的最终目标是使用这些独特的标签,然后通过以下方式生成一个随机的分类标签数组:
rng = np.random.RandomState(101)
categorical_random = rng.choice(list(unique_train_labels), len(finalTestSentences))
categorical_random_threshold = rng.choice(list(unique_train_labels_threshold), len(finalTestSentences))
从docs 中说set.add() 应该生成一个新集合,但似乎并非如此(因此我以后不能调用list(unique_train_labels_threshold))
【问题讨论】:
-
文档在哪里说 add 方法生成一个新集合?我只发现:s.add(x) add element x to set s
-
你应该这样做 int 2 次。首先将
unique_train_labels存储在unique_train_labels_threshold中,然后在unique_train_labels_threshold上调用add(),a_set.add(stuff)总是return none -
@cdarke 是的,这就是我的意思,它说它向集合中添加了一个元素,这对我来说似乎意味着集合应该仍然存在..
-
@pwnsauce 你能澄清一下我能做些什么以便我可以使用新的集合
a_set.add(stuff)吗?
标签: python python-2.7 numpy random set