在 Julia 中获取加法标识元素 – zero() 方法
zero()
是 julia 中的一个内置函数,用于返回 x 类型的加法标识元素,其中 x 也可能是类型本身。
Syntax: zero(x)
Parameters:
- x: Specified value.
Returns: It returns the additive identity element for the type of x, where x might also be type itself.
示例 1:
# Julia program to illustrate
# the use of zero() method
# Getting the additive identity element
# for the type of given parameter
println(zero(0))
println(zero(1))
println(zero(5.6))
println(zero(big"2.0"))
输出:
示例 2:
# Julia program to illustrate
# the use of zero() method
# Getting the additive identity element
# for the type of given parameter
println(zero(rand(1, 1)))
println(zero(rand(2, 2)))
println(zero(rand(3, 3)))
输出:
[0.0]
[0.0 0.0; 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]