Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Work with symmetric matrices by checking whether a square matrix equals its transpose and, if it is symmetric, returning its symmetric part.
Implement the function
Rules:
A as symmetric if the maximum absolute entry-wise difference between A and A^T is at most 1e-9.A is not symmetric.Output:
| Argument | Type |
|---|---|
| A | np.ndarray |
| Return Name | Type |
|---|---|
| value | tuple |
Input/output must be NumPy arrays.
Square matrix; use tolerance 1e-9.
Symmetry check: compare A with A.T using np.abs(A - A.T) and find the maximum difference.
Use the tolerance rule: is_symmetric = (max_diff <= 1e-9).
Compute symmetric part vectorized: S = 0.5 * (A + A.T).