本文整理汇总了Python中skbio.core.distance.DissimilarityMatrix.filter方法的典型用法代码示例。如果您正苦于以下问题:Python DissimilarityMatrix.filter方法的具体用法?Python DissimilarityMatrix.filter怎么用?Python DissimilarityMatrix.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.core.distance.DissimilarityMatrix
的用法示例。
在下文中一共展示了DissimilarityMatrix.filter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_asymmetric
# 需要导入模块: from skbio.core.distance import DissimilarityMatrix [as 别名]
# 或者: from skbio.core.distance.DissimilarityMatrix import filter [as 别名]
def test_filter_asymmetric(self):
# 2x2
ids = ['b', 'a']
exp = DissimilarityMatrix([[0, -2], [1, 0]], ids)
obs = self.dm_2x2_asym.filter(ids)
self.assertEqual(obs, exp)
# 3x3
dm = DissimilarityMatrix([[0, 10, 53], [42, 0, 22.5], [53, 1, 0]],
('bro', 'brah', 'breh'))
ids = ['breh', 'brah']
exp = DissimilarityMatrix([[0, 1], [22.5, 0]], ids)
obs = dm.filter(ids)
self.assertEqual(obs, exp)
示例2: test_filter_subset
# 需要导入模块: from skbio.core.distance import DissimilarityMatrix [as 别名]
# 或者: from skbio.core.distance.DissimilarityMatrix import filter [as 别名]
def test_filter_subset(self):
ids = ('c', 'a')
exp = DissimilarityMatrix([[0, 4.2], [4.2, 0]], ids)
obs = self.dm_3x3.filter(ids)
self.assertEqual(obs, exp)
ids = ('b', 'a')
exp = DissimilarityMatrix([[0, 0.01], [0.01, 0]], ids)
obs = self.dm_3x3.filter(ids)
self.assertEqual(obs, exp)
# 4x4
dm = DissimilarityMatrix([[0, 1, 55, 7], [1, 0, 16, 1],
[55, 16, 0, 23], [7, 1, 23, 0]])
ids = np.asarray(['3', '0', '1'])
exp = DissimilarityMatrix([[0, 7, 1], [7, 0, 1], [1, 1, 0]], ids)
obs = dm.filter(ids)
self.assertEqual(obs, exp)
示例3: DissimilarityMatrixTests
# 需要导入模块: from skbio.core.distance import DissimilarityMatrix [as 别名]
# 或者: from skbio.core.distance.DissimilarityMatrix import filter [as 别名]
#.........这里部分代码省略.........
self.assertEqual(self.dm_3x3.index('a'), 0)
self.assertEqual(self.dm_3x3.index('b'), 1)
self.assertEqual(self.dm_3x3.index('c'), 2)
with self.assertRaises(MissingIDError):
self.dm_3x3.index('d')
with self.assertRaises(MissingIDError):
self.dm_3x3.index(1)
def test_redundant_form(self):
"""Test retrieving the data matrix in redundant form."""
for dm, redundant in zip(self.dms, self.dm_redundant_forms):
obs = dm.redundant_form()
self.assertTrue(np.array_equal(obs, redundant))
def test_copy(self):
"""Test correct copying of a DissimilarityMatrix."""
copy = self.dm_2x2.copy()
self.assertEqual(copy, self.dm_2x2)
self.assertFalse(copy.data is self.dm_2x2.data)
# deepcopy doesn't actually create a copy of the IDs because it is a
# tuple of strings, which is fully immutable.
self.assertTrue(copy.ids is self.dm_2x2.ids)
new_ids = ['hello', 'world']
copy.ids = new_ids
self.assertNotEqual(copy.ids, self.dm_2x2.ids)
copy = self.dm_2x2.copy()
copy.data[0, 1] = 0.0001
self.assertFalse(np.array_equal(copy.data, self.dm_2x2.data))
def test_filter_no_filtering(self):
# Don't actually filter anything -- ensure we get back a different
# object.
obs = self.dm_3x3.filter(['a', 'b', 'c'])
self.assertEqual(obs, self.dm_3x3)
self.assertFalse(obs is self.dm_3x3)
def test_filter_reorder(self):
# Don't filter anything, but reorder the distance matrix.
order = ['c', 'a', 'b']
exp = DissimilarityMatrix(
[[0, 4.2, 12], [4.2, 0, 0.01], [12, 0.01, 0]], order)
obs = self.dm_3x3.filter(order)
self.assertEqual(obs, exp)
def test_filter_single_id(self):
ids = ['b']
exp = DissimilarityMatrix([[0]], ids)
obs = self.dm_2x2_asym.filter(ids)
self.assertEqual(obs, exp)
def test_filter_asymmetric(self):
# 2x2
ids = ['b', 'a']
exp = DissimilarityMatrix([[0, -2], [1, 0]], ids)
obs = self.dm_2x2_asym.filter(ids)
self.assertEqual(obs, exp)
# 3x3
dm = DissimilarityMatrix([[0, 10, 53], [42, 0, 22.5], [53, 1, 0]],
('bro', 'brah', 'breh'))
ids = ['breh', 'brah']
exp = DissimilarityMatrix([[0, 1], [22.5, 0]], ids)