def test_applying_function_transformation_on_each_element(self): """ Added 16.11.2018 @return: """ def quadratic(value, index0, index1): return value**2 # Creating the array to test on array = np.asarray([[1, 3], [2, 5]]) image = LightningImage(array) # Applying the function image.transform_element_wise(quadratic) # testing each element expected = ([[1, 9], [4, 25]]) self.assertTrue((image.array == expected).all())
def test_applying_function_element_wise_with_outer_scope_variable(self): """ Added 16.11.2018 @return: """ summation = 0 def add(value, index0, index1): nonlocal summation summation += value return value # The array to test on array = np.asarray([[1, 2, 1], [1, 1, 2]]) image = LightningImage(array) # Applying the function image.transform_element_wise(add) self.assertEqual(8, summation)