什么是在ruby中生成正态分布随机数的代码?
(注意:我回答了我自己的问题,但我会等几天才接受是否有人有更好的答案.)
编辑:
搜索到这一点,我查看了两个搜索产生的SO上的所有页面:
+"正态分布"红宝石
和
+高斯+随机红宝石
在elisp我可以评估或作为一个函数就像+.
(or nil 0 nil) ==> 0
(+ 1 0 1) ==> 2
Run Code Online (Sandbox Code Playgroud)
我可以使用apply来将+应用到列表中
(apply '+ '(1 0 1)) ==> 2
Run Code Online (Sandbox Code Playgroud)
所以,我会想或者会以同样的方式工作,但事实并非如此.
(apply 'or '(nil 0 nil)) ==> error: (invalid-function or)
Run Code Online (Sandbox Code Playgroud)
我想这是来自用于实现短路评估的一些内部魔术.如何使用apply对列表执行或操作?
PS我想要的应用程序是找出命令行上的任何元素是否与特定模式匹配,所以我写的重要部分是:
(apply 'or (mapcar (lambda (x) (string-match-p "pattern" x)) command-line-args))
Run Code Online (Sandbox Code Playgroud)
但它不起作用
我已经用try/except块包装了一些内存不足的代码.但是,虽然生成了MemoryError,但它没有被捕获.
我有以下代码:
while True:
try:
self.create_indexed_vocab( vocab )
self.reset_weights()
break;
except MemoryError:
# Stuff to reduce size of vocabulary
self.vocab, self.index2word = None, None
self.syn0, self.syn1 = None, None
self.min_count += 1
logger.info( ...format string here... )
Run Code Online (Sandbox Code Playgroud)
我得到以下Traceback:
File "./make_model_tagged_wmt11.py", line 39, in <module>
model.build_vocab(sentences)
File "/root/CustomCompiledSoftware/gensim/gensim/models/word2vec.py", line 236, in build_vocab
self.reset_weights()
File "/root/CustomCompiledSoftware/gensim/gensim/models/word2vec.py", line 347, in reset_weights
self.syn0 += (random.rand(len(self.vocab), self.layer1_size) - 0.5) / self.layer1_size
File "mtrand.pyx", line 1044, in mtrand.RandomState.rand (numpy/random/mtrand/mtrand.c:6523)
File "mtrand.pyx", line 760, in mtrand.RandomState.random_sample (numpy/random/mtrand/mtrand.c:5713) …Run Code Online (Sandbox Code Playgroud)