导入数学和类型错误:“内置函数或方法”对象不可下标

2024-09-24 00:26:40 发布

您现在位置:Python中文网/ 问答频道 /正文

import math as m

def get_distance(latx,lonx,latp,lonp):
    '''
    Calculate the angular distance from point, x, to pole, p.
    Inputs and outputs should be in radians.
    '''
    # YOUR CODE HERE

    angular_distance = m.cos[m.sin(latx)*m.sin(latp)+m.cos(latx)*m.cos(latp)*m.cos(lonp-lonx)]
    print(angular_distance)
    raise NotImplementedError()

get_distance(48,50,87,22)
Traceback (most recent call last):
  File "C:\Users\13609\Documents\Search\dg.py", line 14, in <module>
    get_distance(48,50,87,22)
  File "C:\Users\13609\Documents\Search\dg.py", line 10, in get_distance
    angular_distance = m.cos[m.sin(latx)*m.sin(latp)+m.cos(latx)*m.cos(latp)*m.cos(lonp-lonx)]
TypeError: 'builtin_function_or_method' object is not subscriptable


Tags: insearchgetsincosusersdocumentsfile
1条回答
网友
1楼 · 发布于 2024-09-24 00:26:40

调用m.cos时需要使用括号。 方法调用应如下所示:

m.cos(m.sin(latx)*m.sin(latp)+m.cos(latx)*m.cos(latp)*m.cos(lonp-lonx))

相关问题 更多 >