import numpy as np
a = np.arange(10)
a_diff = np.diff(a,2)
# 是否等差
~np.any(a_diff)
def isArithmetic(a):
return ~np.any(np.diff(a,2))
# 当然函数没有容错性考虑,仅仅实现了功能
import numpy as np
a = np.arange(10)
a_diff = np.diff(a,2)
# 是否等差
~np.any(a_diff)
def isArithmetic(a):
return ~np.any(np.diff(a,2))
# 当然函数没有容错性考虑,仅仅实现了功能
本文标题:在python中判断一个数组或列表是否为等差数列
本文链接:https://www.haomeiwen.com/subject/vwpcmxtx.html
网友评论