- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否有一种方法可以不用像 $b = $a * -1
这样的乘法将正数变成负数我正在寻找成本最合理的方法,因为我要在脚本中多次执行此操作。
-编辑在这一点上,我正在使用它,但在计算方面看起来非常昂贵:
$temp_array = New-Object 'object[,]' $this.row,$this.col
for ($i=0;$i -le $this.row -1 ; $i++) {
for ($j=0;$j -le $this.col -1 ; $j++) {
$digit = $this.data[$i,$j] * -1
$temp_array[$i,$j] = 1 / ( 1 + [math]::exp( $digit ) )
#[math]::Round( $digit ,3)
}
}
$this.data = $temp_array
最佳答案
要无条件地将一个正数转换为它的负数(或者,更一般地说,翻转一个数字的符号),只需使用一元-
运算符:
PS> $v = 10; -$v
-10
适用于您的情况:
$digit = -$this.data[$i,$j]
顺便说一句:如果性能很重要,您可以通过使用..
来加速循环,range operator 创建要迭代的索引:
$temp_array = New-Object 'object[,]' $this.row,$this.col
for ($i in 0..($this.row-1)) {
for ($j in 0..($this.col-1)) {
$digit = - $this.data[$i,$j]
$temp_array[$i,$j] = 1 / ( 1 + [math]::exp( $digit ) )
}
}
$this.data = $temp_array
关于powershell - 在 powershell 中有一种方法可以不用乘法将正数变成负数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52634418/
所以我目前正在代码 war 中解决以下问题: 返回一个数组,其中第一个元素是正数的计数,第二个元素是负数的总和。如果输入数组为空或 null,则返回一个空数组。 我想出了下面的代码,它并不漂亮,但我知
我想禁用文本框中的字母,这就是我使用此表达式的原因: /^[0-9]*$/ 问题是我也想允许负数, 这个表达式不允许我使用减号。(-)..我该怎么办? 最佳答案 尝试使用以下正则表达式: /^-?[0
这是一道面试题。我们有一个正整数数组,我们必须重新排列和连接数组元素,以便生成的数字是可以使用此数组形成的最大数字。 例如: [884 88] -> 88884 [20 19 90] -> 90201
所以我有点无奈。我想我了解如何对 IEEE-754 数字进行加法,但我在减法方面遇到了很大的问题。我感觉我的想法是对的,但我想和大家确认一下。 因此我们有以下两个 IEEE-754 编号: x: 0
我想将一个正数转换成相应的数字列表——数字也应该是整数。 转换时,比如1024,应该返回[1,0,2,4] 最佳答案 在 Swift 4.1 或更高版本中 let number = 1024 let
如果 float 可以用来正确表示我将使用的参数范围,我正在尝试为我的音频应用程序弄清楚。 它需要的“最大”掩码用于频率参数,它是正的,并且允许最多两位数字作为尾数(即从 20.00 hz 到 220
我是一名优秀的程序员,十分优秀!