MCPcopy Create free account
hub / github.com/modAL-python/modAL / data_hstack

Function data_hstack

modAL/utils/data.py:44–69  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

42
43
44def 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
72def add_row(X: modALinput, row: modALinput):

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…