查看: 1877|回复: 1

numpy.intersect1d

[复制链接]

665

主题

1234

帖子

6576

积分

xdtech

Rank: 5Rank: 5

积分
6576
发表于 2019-1-2 11:12:18 | 显示全部楼层 |阅读模式
本帖最后由 shaoheshaohe 于 2019-1-2 11:13 编辑

numpy.intersect1d(ar1, ar2, assume_unique=False)[source]Find the intersection of two arrays.
Return the sorted, unique values that are in both of the input arrays.


Parameters:
ar1, ar2 : array_like
Input arrays.

assume_unique : bool
If True, the input arrays are both assumed to be unique, whichcan speed up the calculation.  Default is False.

Returns:
intersect1d : ndarray
Sorted 1D array of common and unique elements.


See also
numpy.lib.arraysetops
Module with a number of other functions for performing set operations on arrays.


Examples
>>>>>> np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1])
array([1, 3])

To intersect more than two arrays, use functools.reduce:
>>>>>> from functools import reduce
>>> reduce(np.intersect1d, ([1, 3, 4, 3], [3, 1, 2, 1], [6, 3, 4, 2]))
array([3])


回复

使用道具 举报

166

主题

616

帖子

1万

积分

xdtech

Rank: 5Rank: 5

积分
10828
发表于 2019-1-13 09:24:38 | 显示全部楼层
这就是求交集
的方法
用起来很方便

就是一个问题
需要求多个集合的交集,怎么干呢?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表