通用函数测试

import numpy as np

# 通用函数
ary = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
ary1 = np.clip(ary, 3, 7)  # ary.clip(min = 3, max = 7)
# print(ary1)
ary2 = ary.compress(ary > 5)  # ary[ary > 5]
# print(ary2)
mask = np.all([ary > 3, ary < 7], axis=0)
# print(mask)
# print([3 < ary < 7])  # 错误写法
# print(ary[mask])  # 借助all(),any()函数去实现多个条件,不要忘记掩码技术

# a = np.arange(1, 6)
# print(np.add(a, a))
# print(np.add.reduce(a))
# print(np.add.accumulate(a))
# print(a.prod())
# print(a.cumprod())



上一篇:python3 Robot Framework-设置失败用例重试


下一篇:设计模式-Note9-行为变化类