Stack horizontally sparse/dense arrays and pandas data frames. Args: blocks: Sequence of modALinput objects. Returns: New sequence of horizontally stacked elements.
(blocks: Sequence[modALinput])
| 42 | |
| 43 | |
| 44 | def data_hstack(blocks: Sequence[modALinput]) -> modALinput: |
| 45 | """ |
| 46 | Stack horizontally sparse/dense arrays and pandas data frames. |
| 47 | |
| 48 | Args: |
| 49 | blocks: Sequence of modALinput objects. |
| 50 | |
| 51 | Returns: |
| 52 | New sequence of horizontally stacked elements. |
| 53 | """ |
| 54 | if any([sp.issparse(b) for b in blocks]): |
| 55 | return sp.hstack(blocks) |
| 56 | elif isinstance(blocks[0], pd.DataFrame): |
| 57 | pd.concat(blocks, axis=1) |
| 58 | elif isinstance(blocks[0], np.ndarray): |
| 59 | return np.hstack(blocks) |
| 60 | elif isinstance(blocks[0], list): |
| 61 | return np.hstack(blocks).tolist() |
| 62 | |
| 63 | try: |
| 64 | if torch.is_tensor(blocks[0]): |
| 65 | return torch.cat(blocks, dim=1) |
| 66 | except: |
| 67 | pass |
| 68 | |
| 69 | TypeError("%s datatype is not supported" % type(blocks[0])) |
| 70 | |
| 71 | |
| 72 | def add_row(X: modALinput, row: modALinput): |
no outgoing calls
no test coverage detected
searching dependent graphs…