Esempio n. 1
0
    def from_points(cls, points):
        if points.ndim != 2:
            raise ValueError('"points" should have two dimensions.')
        if points.shape[0] < 3:
            raise ValueError('"points" should contain at least 3 points.')
        if points.shape[1] != 3:
            raise ValueError('"points" should be X*3 (x,y,z).')

        return cls(points, points.shape[0], DistanceMatrix.from_points(points))
Esempio n. 2
0
    def test_get_flatten_upper_triangular_matrix(self):
        points = np.array([
            [1, 0, 0],
            [2, 0, 0],
            [3, 0, 0],
            [4, 0, 0],
        ])
        distance_matrix = DistanceMatrix.from_points(points)
        flatten_upper_triangular_matrix = distance_matrix.get_futm()

        correct_flatten_upper_triangular_matrix = [
            1.0, 2.0, 3.0, 1.0, 2.0, 1.0
        ]
        self.assertEqual(flatten_upper_triangular_matrix,
                         correct_flatten_upper_triangular_matrix)
Esempio n. 3
0
    def test___init__(self):
        points = np.array([
            [1, 0, 0],
            [2, 0, 0],
            [3, 0, 0],
            [4, 0, 0],
        ])
        distance_matrix = DistanceMatrix.from_points(points)

        correct_distance_matrix = np.array([
            [0, 1, 2, 3],
            [1, 0, 1, 2],
            [2, 1, 0, 1],
            [3, 2, 1, 0],
        ])
        self.assertEqual(distance_matrix.size, 4)
        self.assertTrue(
            np.array_equal(distance_matrix.distance_matrix_nparray,
                           correct_distance_matrix))