improve solution to exercise 82
The current solution uses a fixed arbitrary threshold of 1e-10 on the singular values, I replaced it with the common heuristic n*eps*max(s).
This commit is contained in:
@@ -993,7 +993,8 @@ print(sliding_window_view(Z, window_shape=4))
|
||||
|
||||
Z = np.random.uniform(0,1,(10,10))
|
||||
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
||||
rank = np.sum(S > 1e-10)
|
||||
threshold = len(S) * S.max() * np.finfo(S.dtype).eps
|
||||
rank = np.sum(S > threshold)
|
||||
print(rank)
|
||||
|
||||
# alternative solution:
|
||||
|
||||
@@ -993,7 +993,8 @@ print(sliding_window_view(Z, window_shape=4))
|
||||
|
||||
Z = np.random.uniform(0,1,(10,10))
|
||||
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
||||
rank = np.sum(S > 1e-10)
|
||||
threshold = len(S) * S.max() * np.finfo(S.dtype).eps
|
||||
rank = np.sum(S > threshold)
|
||||
print(rank)
|
||||
|
||||
# alternative solution:
|
||||
|
||||
@@ -1225,7 +1225,8 @@ hint: np.linalg.svd, np.linalg.matrix_rank
|
||||
|
||||
Z = np.random.uniform(0,1,(10,10))
|
||||
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
||||
rank = np.sum(S > 1e-10)
|
||||
threshold = len(S) * S.max() * np.finfo(S.dtype).eps
|
||||
rank = np.sum(S > threshold)
|
||||
print(rank)
|
||||
|
||||
# alternative solution:
|
||||
|
||||
Reference in New Issue
Block a user