| import numpy as np |
| import scipy.io as sio |
|
|
| def load_mat_as_numeric(path, x_key="X", y_key="Y"): |
| data = sio.loadmat(path) |
| X_raw = data[x_key] |
| y_raw = data[y_key] |
|
|
| |
| def clean_cell_array(arr): |
| cleaned = [] |
| for row in arr: |
| new_row = [] |
| for elem in row: |
| |
| if isinstance(elem, np.ndarray): |
| elem = elem[0] |
| elem = elem.strip() |
| new_row.append(elem) |
| cleaned.append(new_row) |
| return np.array(cleaned) |
|
|
| X_str = clean_cell_array(X_raw) |
| y_str = clean_cell_array(y_raw).reshape(-1) |
|
|
| |
| X = X_str.astype(float) |
|
|
| |
| try: |
| y = y_str.astype(float) |
| except: |
| y = y_str.astype(str) |
|
|
| return X, y |
|
|