for i, x in enumerate_data(X): Depending on the data type of X, returns: * A 1xM matrix in case of scipy sparse NxM matrix X * pandas series in case of a pandas data frame X * row in case of list or numpy format
(X: modALinput)
| 149 | |
| 150 | |
| 151 | def enumerate_data(X: modALinput): |
| 152 | """ |
| 153 | for i, x in enumerate_data(X): |
| 154 | |
| 155 | Depending on the data type of X, returns: |
| 156 | |
| 157 | * A 1xM matrix in case of scipy sparse NxM matrix X |
| 158 | * pandas series in case of a pandas data frame X |
| 159 | * row in case of list or numpy format |
| 160 | """ |
| 161 | if sp.issparse(X): |
| 162 | return enumerate(X.tocsr()) |
| 163 | elif isinstance(X, pd.DataFrame): |
| 164 | return X.iterrows() |
| 165 | elif isinstance(X, np.ndarray) or isinstance(X, list): |
| 166 | # numpy arrays and lists can readily be enumerated |
| 167 | return enumerate(X) |
| 168 | |
| 169 | raise TypeError("%s datatype is not supported" % type(X)) |
| 170 | |
| 171 | |
| 172 | def data_shape(X: modALinput): |
no outgoing calls
no test coverage detected
searching dependent graphs…