np.copysign_带有Python示例的math.copysign()方法

np.copysign

Python math.copysign()方法 (Python math.copysign() method)

math.copysign() method is a library method of math module, it is used to get a number with the sign of another number, it accepts two numbers (either integers or floats) and returns a float value of the first number with the sign of the second number.

math.copysign()方法数学模块的库方法,用于获取带有另一个数字的符号的数字,它接受两个数字(整数或浮点数)并返回带有符号的第一个数字的浮点值第二个数字。

Note: If anything is passed except the number, the method returns a type error, "TypeError: a float is required".

注意:如果传递了除数字以外的任何内容,则该方法将返回类型错误“ TypeError:需要浮点数”。

Syntax of math.copysign() method:

math.copysign()方法的语法:

    math.copysign(x, y)

Parameter(s): x, y – two numbers, x to be converted and y whose sign is required.

参数: x,y –两个数字, x是要转换的, y是需要符号的。

Return value: float – it returns a float value, that is x with the sign of y.

返回值: float-它返回一个浮点值,即x和y的符号。

Example:

例:

    Input:
    a = 10
    b = -2

    # function call
    print(math.copysign(a, b))

    Output:
    -10.0

Python代码演示math.copysign()方法的示例 (Python code to demonstrate example of math.copysign() method)

# Python code demonstrate example of 
# math.copysign() method
import math

# numbers
a = 10
b = -2
print("copysign(a,b): ", math.copysign(a,b))

a = -10
b = -2
print("copysign(a,b): ", math.copysign(a,b))

a = 10.23
b = -2
print("copysign(a,b): ", math.copysign(a,b))

a = -10.23
b = -2.34
print("copysign(a,b): ", math.copysign(a,b))

a = -10
b = 2
print("copysign(a,b): ", math.copysign(a,b))

Output

输出量

copysign(a,b):  -10.0
copysign(a,b):  -10.0
copysign(a,b):  -10.23
copysign(a,b):  -10.23
copysign(a,b):  10.0


翻译自: https://www.includehelp.com/python/math-copysign-method-with-example.aspx

np.copysign

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值