numpy.random函数中未知* [英] Unknown * in numpy.random function
本文介绍了numpy.random函数中未知*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究此链接,这是代码.
I was studying this link and this is the code .
U1 = np.random.rand(*H1.shape) < p # first dropout mask
为什么我尝试这样做会失败?
Why does it fail when I try to do this?
import numpy
numpy.random.rand(*1) < 2
我知道rand()
函数接受一个数字,这就是为什么我对代码应该起作用感到困惑的原因.
I understand that the rand()
function takes in a number which is why I am confused that the code is supposed to work.
推荐答案
*
将元组解包为多个输入参数.该代码使用shape
属性(它是一个元组)作为np.random.rand
的尺寸输入,创建与H1
形状相同的随机矩阵.
The *
unpacks a tuple into multiple input arguments. The code is creating a random matrix the same shape as H1
using the shape
attribute (which is a tuple) as the dimension inputs to np.random.rand
.
您可以使用任何元组执行此操作
You can do this with any tuple
np.random.rand(*(2,3)) # The same as np.random.rand(2,3)
# Creates a 2 x 3 array
您正试图解压缩将失败的整数.
You are trying to unpack an integer which is going to fail.
这篇关于numpy.random函数中未知*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文