本文整理汇总了Python中numpy.lib.arraysetops.in1d函数的典型用法代码示例。如果您正苦于以下问题:Python in1d函数的具体用法?Python in1d怎么用?Python in1d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了in1d函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_in1d
def test_in1d(self):
# we use two different sizes for the b array here to test the
# two different paths in in1d().
for mult in (1, 10):
# One check without np.array, to make sure lists are handled correct
a = [5, 7, 1, 2]
b = [2, 4, 3, 1, 5] * mult
ec = np.array([True, False, True, True])
c = in1d(a, b, assume_unique=True)
assert_array_equal(c, ec)
a[0] = 8
ec = np.array([False, False, True, True])
c = in1d(a, b, assume_unique=True)
assert_array_equal(c, ec)
a[0], a[3] = 4, 8
ec = np.array([True, False, True, False])
c = in1d(a, b, assume_unique=True)
assert_array_equal(c, ec)
a = np.array([5, 4, 5, 3, 4, 4, 3, 4, 3, 5, 2, 1, 5, 5])
b = [2, 3, 4] * mult
ec = [False, True, False, True, True, True, True, True, True, False,
True, False, False, False]
c = in1d(a, b)
assert_array_equal(c, ec)
b = b + [5, 5, 4] * mult
ec = [True, True, True, True, True, True, True, True, True, True,
True, False, True, True]
c = in1d(a, b)
assert_array_equal(c, ec)
a = np.array([5, 7, 1, 2])
b = np.array([2, 4, 3, 1, 5] * mult)
ec = np.array([True, False, True, True])
c = in1d(a, b)
assert_array_equal(c, ec)
a = np.array([5, 7, 1, 1, 2])
b = np.array([2, 4, 3, 3, 1, 5] * mult)
ec = np.array([True, False, True, True, True])
c = in1d(a, b)
assert_array_equal(c, ec)
a = np.array([5, 5])
b = np.array([2, 2] * mult)
ec = np.array([False, False])
c = in1d(a, b)
assert_array_equal(c, ec)
a = np.array([5])
b = np.array([2])
ec = np.array([False])
c = in1d(a, b)
assert_array_equal(c, ec)
assert_array_equal(in1d([], []), [])
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:59,代码来源:test_arraysetops.py
示例2: test_in1d_invert
def test_in1d_invert(self):
"Test in1d's invert parameter"
# We use two different sizes for the b array here to test the
# two different paths in in1d().
for mult in (1, 10):
a = np.array([5, 4, 5, 3, 4, 4, 3, 4, 3, 5, 2, 1, 5, 5])
b = [2, 3, 4] * mult
assert_array_equal(np.invert(in1d(a, b)), in1d(a, b, invert=True))
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:8,代码来源:test_arraysetops.py
示例3: common_timesteps
def common_timesteps(timegridA, timegridB):
r"""
Find the indices (wrt to A and B) of the timesteps common to both timegrids.
"""
IA = in1d(timegridA, timegridB)
IB = in1d(timegridB, timegridA)
return (IA, IB)
开发者ID:WaveBlocks,项目名称:WaveBlocks,代码行数:8,代码来源:Utils.py
示例4: test_in1d_ravel
def test_in1d_ravel(self):
# Test that in1d ravels its input arrays. This is not documented
# behavior however. The test is to ensure consistentency.
a = np.arange(6).reshape(2, 3)
b = np.arange(3, 9).reshape(3, 2)
long_b = np.arange(3, 63).reshape(30, 2)
ec = np.array([False, False, False, True, True, True])
assert_array_equal(in1d(a, b, assume_unique=True), ec)
assert_array_equal(in1d(a, b, assume_unique=False), ec)
assert_array_equal(in1d(a, long_b, assume_unique=True), ec)
assert_array_equal(in1d(a, long_b, assume_unique=False), ec)
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:12,代码来源:test_arraysetops.py
示例5: test_in1d_char_array
def test_in1d_char_array(self):
a = np.array(['a', 'b', 'c', 'd', 'e', 'c', 'e', 'b'])
b = np.array(['a', 'c'])
ec = np.array([True, False, True, False, False, True, False, False])
c = in1d(a, b)
assert_array_equal(c, ec)
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:8,代码来源:test_arraysetops.py
示例6: ghost_bnd_layer
def ghost_bnd_layer(ghosttri, tlower, tupper, mesh, p):
boundary = mesh.boundary
ghost_list = []
subboundary = {}
new_ghost_list = ghosttri[:,0]
#print new_ghost_list
# 0 edge boundaries
nghb0 = mesh.neighbours[new_ghost_list,0]
gl0 = num.extract(num.logical_or(nghb0 < tlower, nghb0 >= tupper), new_ghost_list)
nghb0 = mesh.neighbours[gl0,0]
flag = numset.in1d(nghb0,new_ghost_list)
gl0 = num.extract(num.logical_not(flag),gl0)
edge0 = 0*num.ones_like(gl0)
n0 = len(edge0)
values0 = ['ghost']*n0
# 1 edge boundary
nghb1 = mesh.neighbours[new_ghost_list,1]
gl1 = num.extract(num.logical_or(nghb1 < tlower, nghb1 >= tupper), new_ghost_list)
nghb1 = mesh.neighbours[gl1,1]
flag = numset.in1d(nghb1,new_ghost_list)
gl1 = num.extract(num.logical_not(flag),gl1)
edge1 = 1*num.ones_like(gl1)
n1 = len(edge1)
values1 = ['ghost']*n1
# 2 edge boundary
nghb2 = mesh.neighbours[new_ghost_list,2]
gl2 = num.extract(num.logical_or(nghb2 < tlower, nghb2 >= tupper), new_ghost_list)
nghb2 = mesh.neighbours[gl2,2]
flag = numset.in1d(nghb2,new_ghost_list)
gl2 = num.extract(num.logical_not(flag),gl2)
edge2 = 2*num.ones_like(gl2)
n2 = len(edge2)
values2 = ['ghost']*n2
gl = num.concatenate((gl0,gl1,gl2))
edge = num.concatenate((edge0,edge1,edge2))
values = values0 + values1 + values2
# print gl
# print edge
# print values
subboundary = dict(zip(zip(gl,edge),values))
#intersect with boundary
# FIXME SR: these keys should be viewkeys but need python 2.7
subboundary.update( (k,boundary[k]) for k in set(subboundary.keys()) & set(boundary.keys()) )
#print subboundary
return subboundary
开发者ID:MattAndersonPE,项目名称:anuga_core,代码行数:61,代码来源:distribute_mesh.py
注:本文中的numpy.lib.arraysetops.in1d函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论