记录一些Numpy的奇奇怪怪的方法和函数
np.in1d查看数组1(数组2)的某元素是否存在与数组2(数组1)
ar1 = np.array([1,2,3])
ar2 = np.array([3,2,1])
a = np.in1d(ar1, ar2, assume_unique=False, invert=False)
print(a) # [ True True True]
ar1 = np.array([1,2,3])
ar2 = np.array([3,2,1])
a = np.in1d(ar1, ar2, assume_unique=False, invert=True)
print(a) # [False False False]
ar1 = np.array([1,2,3])
ar2 = np.array([3,2,1])
a = np.in1d(ar1, ar2, assume_unique=True, invert=True)
print(a) # [False False False]
ar1 = np.array([8,100,2,3])
ar2 = np.array([3,2,1])
a = np.in1d(ar1, ar2, assume_unique=False, invert=False)
print(a) # [False False True True]
ar1 = np.array([8,100,2,3])
ar2 = np.array([3,2,1])
a = np.in1d(ar1, ar2, assume_unique=False, invert=True)
print(a) # [ True True False False]
ar1 = np.array([8,100,2,3])
ar2 = np.array([3,2,1])
a = np.in1d(ar1, ar2, assume_unique=True, invert=True)
print(a) # [ True True False False]
Numpy随机抽取
按照从0到k的范围取样取出num个整数,返回一个list,
randient似乎有整数的意思
np.random.randint(0, k, num)
result = random.randint(1,10) #返回 [1, 10] 之间的任意整数
从列表中抽取3个元素
x = np.random.choice([], k=3)
要想不重复,
x = np.random.choice([], k=3,repalce=False)
从0到k的范围中抽取n个数字,允许重复
a = np.random.randint(k, size=n)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)