I have two numpy 3d arrays with dimension of m-n-n: arr1 and arr2. Each inner array is a square matrix (n-n). In my unittest work, arr1 and arr2 should be the same, except that any column in any inner matrix in arr1 can have a different sign than that in arr2. I want to mimic the function numpy.testing.assert_almost_equal(arr1, arr2). It should output True even if there are some columns have different sign. Could you please show me how to realize it? Thanks in advance!
Here is an example below. In the 1st inner matrix, the 2nd column has a different sign; in the 2nd inner matrix, the 3rd column has a different sign; and the 3rd inner matrix has the same sign. Note that, the different sign is applied to a whole column, not a part of it.
import numpy as np
arr1 = np.array([
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
],
[
[10, 20, 30],
[40, 50, 60],
[70, 80, 90]
],
[
[100, 200, 300],
[400, 500, 600],
[700, 800, 900]
]
])
arr2 = np.array([
[
[1, -2, 3],
[4, -5, 6],
[7, -8, 9]
],
[
[10, 20, -30],
[40, 50, -60],
[70, 80, -90]
],
[
[100, 200, 300],
[400, 500, 600],
[700, 800, 900]
]
])
np.testing.assert_almost_equal(arr1, arr2) # How to re-write it so that the comparison results is `True`?