python中的数开方后为什么都变成1了import numpy as npc = 0.1a = np.sqrt(3)X = np.arange(-3,3,0.01)Y = np.arange(-3,3,0.01)X,Y = np.meshgrid(X,Y)R = (c**2 + 4*c**2*np.cos(X)**2 + 4*c**2*np.cos(X)*np.cos(a*Y) - 0.25)A = R**(1/2)Z = np.real(A
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/05 14:33:12
python中的数开方后为什么都变成1了import numpy as npc = 0.1a = np.sqrt(3)X = np.arange(-3,3,0.01)Y = np.arange(-3,3,0.01)X,Y = np.meshgrid(X,Y)R = (c**2 + 4*c**2*np.cos(X)**2 + 4*c**2*np.cos(X)*np.cos(a*Y) - 0.25)A = R**(1/2)Z = np.real(A
python中的数开方后为什么都变成1了
import numpy as np
c = 0.1
a = np.sqrt(3)
X = np.arange(-3,3,0.01)
Y = np.arange(-3,3,0.01)
X,Y = np.meshgrid(X,Y)
R = (c**2 + 4*c**2*np.cos(X)**2 + 4*c**2*np.cos(X)*np.cos(a*Y) - 0.25)
A = R**(1/2)
Z = np.real(A)
print A
这是我的代码 运行之后 发现A全是1,可是R并不是全是1,这是怎么回事的
python中的数开方后为什么都变成1了import numpy as npc = 0.1a = np.sqrt(3)X = np.arange(-3,3,0.01)Y = np.arange(-3,3,0.01)X,Y = np.meshgrid(X,Y)R = (c**2 + 4*c**2*np.cos(X)**2 + 4*c**2*np.cos(X)*np.cos(a*Y) - 0.25)A = R**(1/2)Z = np.real(A
将A=R**(1/2)
改为
A=R**0.5 或 A=R**(1.0/2)
python 2中整数的除法是向下取整的,1/2为0,因此 A=R**(1/2) 计算的是R的0次方