AlvLouWeh2017: Remove slow loop in M3

master
Alinson S. Xavier 4 years ago
parent f2b710e9f9
commit 9e023a375a

@ -356,17 +356,8 @@ class FeaturesExtractor:
push(np.abs(v)) push(np.abs(v))
def maxmin(M: np.ndarray) -> Tuple[np.ndarray, np.ndarray]: def maxmin(M: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
# Compute max using regular numpy operations
M_max = np.ravel(M.max(axis=0).todense()) M_max = np.ravel(M.max(axis=0).todense())
M_min = np.ravel(M.min(axis=0).todense())
# Compute min by iterating through the sparse matrix data, so that
# we skip non-zero entries
M_min = np.array(
[
0.0 if len(M[:, j].data) == 0 else M[:, j].data.min()
for j in range(M.shape[1])
]
)
return M_max, M_min return M_max, M_min
with np.errstate(divide="ignore", invalid="ignore"): with np.errstate(divide="ignore", invalid="ignore"):

Loading…
Cancel
Save