本文整理匯總了Python中skbio.core.distance.DissimilarityMatrix.index方法的典型用法代碼示例。如果您正苦於以下問題:Python DissimilarityMatrix.index方法的具體用法?Python DissimilarityMatrix.index怎麽用?Python DissimilarityMatrix.index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類skbio.core.distance.DissimilarityMatrix
的用法示例。
在下文中一共展示了DissimilarityMatrix.index方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: DissimilarityMatrixTests
# 需要導入模塊: from skbio.core.distance import DissimilarityMatrix [as 別名]
# 或者: from skbio.core.distance.DissimilarityMatrix import index [as 別名]
#.........這裏部分代碼省略.........
def test_ids_invalid_input(self):
"""Test setting invalid IDs raises an error."""
with self.assertRaises(DissimilarityMatrixError):
self.dm_3x3.ids = ['foo', 'bar']
# Make sure that we can still use the dissimilarity matrix after trying
# to be evil.
obs = self.dm_3x3.ids
self.assertEqual(obs, ('a', 'b', 'c'))
def test_dtype(self):
"""Test retrieving dtype of data matrix."""
for dm in self.dms:
self.assertEqual(dm.dtype, np.float64)
def test_shape(self):
"""Test retrieving shape of data matrix."""
for dm, shape in zip(self.dms, self.dm_shapes):
self.assertEqual(dm.shape, shape)
def test_size(self):
"""Test retrieving size of data matrix."""
for dm, size in zip(self.dms, self.dm_sizes):
self.assertEqual(dm.size, size)
def test_transpose(self):
"""Test retrieving transpose of dissimilarity matrix."""
for dm, transpose in zip(self.dms, self.dm_transposes):
self.assertEqual(dm.T, transpose)
self.assertEqual(dm.transpose(), transpose)
# We should get a reference to a different object back, even if the
# transpose is the same as the original.
self.assertTrue(dm.transpose() is not dm)
def test_index(self):
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))