【发布时间】:2021-07-14 05:41:06
【问题描述】:
我正在尝试编写一个名为my_within_tolerance(A, a, tol) 的函数。 A 可以是浮点数列表或数组,而 a 和 tol 是浮点数。该函数应返回 A 中的元素 |A − a|
我是 python 新手。
这是我写的:
import numpy as np
def my_within_tolerance(A, a, tol):
A=np.asarray(A)
if((abs(A-a)<tol).any()):
return A
print(my_within_tolerance([0, 1, 2, 3], 1.5, 0.75))
输出应该是:
[1, 2]
【问题讨论】:
标签: python arrays python-3.x list function