通用函数测试
作者:互联网
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())
标签:通用,函数,clip,ary,mask,np,add,测试,print 来源: https://blog.csdn.net/qq_45298704/article/details/120697334