2 条题解
-
0
NUMPY032 题解:复数开方比较
题目
判断以下表达式是否相等:
np.sqrt(-1) == np.emath.sqrt(-1)解题思路
理解普通 sqrt 和复数 sqrt 的区别。
代码
import numpy as np print(np.sqrt(-1) == np.emath.sqrt(-1))输出
False详解
np.sqrt(-1)→ nannp.sqrt(-1)- 标准 sqrt 函数
- 负数开方返回
nan(Not a Number) - 因为在实数范围内,负数没有平方根
np.emath.sqrt(-1)→ 1jnp.emath.sqrt(-1)- 复数数学函数
- 返回复数结果
1j - 因为
1j * 1j = -1
数学原理
建议使用
# 使用 emath 处理复数开方 np.emath.sqrt(-1 + 0j) # 确保是复数类型 # 或者手动处理 np.sqrt(x + 0j) # 转换为复数核心知识点
np.sqrt()—— 实数平方根np.emath.sqrt()—— 复数平方根- 负数在实数范围内无平方根
- 1
信息
- ID
- 83
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- (无)
- 递交数
- 0
- 已通过
- 0
- 上传者