【发布时间】:2019-11-22 21:17:27
【问题描述】:
所以基本上我有多个数组,我需要用这些数组计算一些东西。问题是这些数组中的一些有时等于零并且是除数。
我想通过过滤我的数组并说出类似“if r >= rs: print("0"), else: print(H)”之类的话来解决这个问题,但它不起作用。我还尝试使用 map 函数来表示如果半径 r
def Max(r):
if r < 0.00001:
result = 0.00001
else:
result = r
return(result)
# radius array (trying to apply Max to all r)
r22 = map(Max, zz[:, 1]) # zz is an odeint function defined before
def Hamiltonian(r, pt, pr, pphi): #all values are given in the code
H = (-((1-rs/r)*-1)(pt*2)/2 + (1-rs/r)(pr*2)/2 + (pphi2)/(2(r**2)))
return(H)
我收到三个错误消息,“TypeError: unsupported operand type(s) for /: 'int' and 'map'”、“TypeError: 'numpy.ndarray' object is not callable”和 TypeError: unsupported operand type (s) for /: 'int' 和 'list'。有谁知道为什么?理想情况下,我希望 H 为所有半径 = 0 自动打印 0 并忽略除以零。谁能帮帮我??
【问题讨论】:
标签: python arrays function numpy-ndarray