Ejemplo n.º 1
0
    def test_binary_transition_a(self) -> None:
        a1 = np.array([False, True, True, False, False, True, True, False])
        self.assertEqual(binary_transition(a1).tolist(), [0, 3, 4, 7])

        a1 = np.array([False, False, True, False, True, True, True, True])
        self.assertEqual(binary_transition(a1).tolist(), [1, 3])


        a1 = np.array([True, False, True])
        self.assertEqual(binary_transition(a1).tolist(), [1])

        a1 = np.array([False, True, False])
        self.assertEqual(binary_transition(a1).tolist(), [0, 2])

        a1 = np.array([True])
        self.assertEqual(binary_transition(a1).tolist(), [])

        a1 = np.array([False])
        self.assertEqual(binary_transition(a1).tolist(), [])

        a1 = np.array([False, True])
        self.assertEqual(binary_transition(a1).tolist(), [0])

        a1 = np.array([True, False])
        self.assertEqual(binary_transition(a1).tolist(), [1])
Ejemplo n.º 2
0
    def test_binary_transition_b(self) -> None:
        # return index per axis (column or row) at False values where False was True, or will be True
        a1 = np.array([[False, False, True, False],
                       [True, False, True, False],
                       [False, False, False, True]
                       ])

        self.assertEqual(
                binary_transition(a1, axis=0).tolist(),
                [(0, 2), None, (2,), (1,)]
                )

        self.assertEqual(
                binary_transition(a1, axis=1).tolist(),
                [(1, 3), (1, 3), (2,)]
                )
Ejemplo n.º 3
0
    def test_binary_transition(self, array: np.ndarray) -> None:
        post = util.binary_transition(array)

        # could be 32 via result of np.nonzero
        self.assertTrue(post.dtype in (np.int32, np.int64))

        # if no True in original array, result will be empty
        if array.sum() == 0:
            self.assertTrue(len(post) == 0)
        # if all True, result is empty
        elif array.sum() == len(array):
            self.assertTrue(len(post) == 0)
        else:
            # the post selection shold always be indices that are false
            self.assertTrue(array[post].sum() == 0)