本文整理汇总了Python中skbio.stats.distance.DissimilarityMatrix._validate方法的典型用法代码示例。如果您正苦于以下问题:Python DissimilarityMatrix._validate方法的具体用法?Python DissimilarityMatrix._validate怎么用?Python DissimilarityMatrix._validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.stats.distance.DissimilarityMatrix
的用法示例。
在下文中一共展示了DissimilarityMatrix._validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DissimilarityMatrixTests
# 需要导入模块: from skbio.stats.distance import DissimilarityMatrix [as 别名]
# 或者: from skbio.stats.distance.DissimilarityMatrix import _validate [as 别名]
#.........这里部分代码省略.........
self.assertTrue(copy == dm)
self.assertFalse(self.dm_1x1 == self.dm_3x3)
def test_ne(self):
# Wrong class.
self.assertTrue(self.dm_3x3 != 'foo')
# Wrong shape.
self.assertTrue(self.dm_3x3 != self.dm_1x1)
# Wrong IDs.
other = self.dm_3x3.copy()
other.ids = ['foo', 'bar', 'baz']
self.assertTrue(self.dm_3x3 != other)
# Wrong data.
other = self.dm_3x3.copy()
other.data[1, 0] = 42.42
self.assertTrue(self.dm_3x3 != other)
self.assertFalse(self.dm_2x2 != self.dm_2x2)
def test_contains(self):
self.assertTrue('a' in self.dm_3x3)
self.assertTrue('b' in self.dm_3x3)
self.assertTrue('c' in self.dm_3x3)
self.assertFalse('d' in self.dm_3x3)
def test_getslice(self):
# Slice of first dimension only. Test that __getslice__ defers to
# __getitem__.
obs = self.dm_2x2[1:]
self.assertTrue(np.array_equal(obs, np.array([[0.123, 0.0]])))
self.assertEqual(type(obs), np.ndarray)
def test_getitem_by_id(self):
obs = self.dm_1x1['a']
self.assertTrue(np.array_equal(obs, np.array([0.0])))
obs = self.dm_2x2_asym['b']
self.assertTrue(np.array_equal(obs, np.array([-2.0, 0.0])))
obs = self.dm_3x3['c']
self.assertTrue(np.array_equal(obs, np.array([4.2, 12.0, 0.0])))
with self.assertRaises(MissingIDError):
self.dm_2x2['c']
def test_getitem_by_id_pair(self):
# Same object.
self.assertEqual(self.dm_1x1['a', 'a'], 0.0)
# Different objects (symmetric).
self.assertEqual(self.dm_3x3['b', 'c'], 12.0)
self.assertEqual(self.dm_3x3['c', 'b'], 12.0)
# Different objects (asymmetric).
self.assertEqual(self.dm_2x2_asym['a', 'b'], 1.0)
self.assertEqual(self.dm_2x2_asym['b', 'a'], -2.0)
with self.assertRaises(MissingIDError):
self.dm_2x2['a', 'c']
def test_getitem_ndarray_indexing(self):
# Single element access.
obs = self.dm_3x3[0, 1]
self.assertEqual(obs, 0.01)
# Single element access (via two __getitem__ calls).
obs = self.dm_3x3[0][1]
self.assertEqual(obs, 0.01)
# Row access.
obs = self.dm_3x3[1]
self.assertTrue(np.array_equal(obs, np.array([0.01, 0.0, 12.0])))
self.assertEqual(type(obs), np.ndarray)
# Grab all data.
obs = self.dm_3x3[:, :]
self.assertTrue(np.array_equal(obs, self.dm_3x3.data))
self.assertEqual(type(obs), np.ndarray)
with self.assertRaises(IndexError):
self.dm_3x3[:, 3]
def test_validate_invalid_dtype(self):
with self.assertRaises(DissimilarityMatrixError):
self.dm_3x3._validate(np.array([[0, 42], [42, 0]]), ['a', 'b'])
def test_pprint_ids(self):
# No truncation.
exp = 'a, b, c'
obs = self.dm_3x3._pprint_ids()
self.assertEqual(obs, exp)
# Truncation.
exp = 'a, b, ...'
obs = self.dm_3x3._pprint_ids(max_chars=5)
self.assertEqual(obs, exp)