【问题标题】:What expression > mean in sentence (python)?什么表达>在句子中的意思(python)?
【发布时间】:2017-06-14 08:20:19
【问题描述】:

这里的输出类型是什么?:

H2 = np.random.rand(*H1.shape) < p   ## p= 0.60    60%

【问题讨论】:

  • 该 numpy 表达式创建了一个布尔数组,其中包含 p True 值(和 1 - p False)。
  • @user7138814 你能给我更多的细节吗?举例
  • 这可能是重复的,但不是链接的。他在问&lt; 运算符在这种情况下的含义,而不是* 运算符

标签: python numpy machine-learning neural-network deep-learning


【解决方案1】:
In [489]: x = np.random.rand(2,3)
In [490]: x
Out[490]: 
array([[ 0.09070037,  0.27653004,  0.14790416],
       [ 0.38391008,  0.1477435 ,  0.63524601]])

查找小于 0.5 的元素:

In [491]: x<.5   
Out[491]: 
array([[ True,  True,  True],
       [ True,  True, False]], dtype=bool)

【讨论】:

    【解决方案2】:

    您的问题是“这里的输出类型是什么”。输出将是一个布尔值(True 或 False),因为它将np.random.rand(*H1.shape) 的结果与p 进行比较。如果p 大于np.random.rand(*H1.shape) H2 将为True。否则 H2 将为 False(如果 np.random.rand(*H1.shape) 等于或小于 p)。

    【讨论】:

      猜你喜欢
      • 2022-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      • 2011-08-15
      • 2011-11-18
      相关资源
      最近更新 更多