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

Function data_vstack

modAL/utils/data.py:16–41  ·  view source on GitHub ↗

Stack vertically sparse/dense arrays and pandas data frames. Args: blocks: Sequence of modALinput objects. Returns: New sequence of vertically stacked elements.

(blocks: Sequence[modALinput])

Source from the content-addressed store, hash-verified

14
15
16def data_vstack(blocks: Sequence[modALinput]) -> modALinput:
17 """
18 Stack vertically sparse/dense arrays and pandas data frames.
19
20 Args:
21 blocks: Sequence of modALinput objects.
22
23 Returns:
24 New sequence of vertically stacked elements.
25 """
26 if any([sp.issparse(b) for b in blocks]):
27 return sp.vstack(blocks)
28 elif isinstance(blocks[0], pd.DataFrame):
29 return blocks[0].append(blocks[1:])
30 elif isinstance(blocks[0], np.ndarray):
31 return np.concatenate(blocks)
32 elif isinstance(blocks[0], list):
33 return np.concatenate(blocks).tolist()
34
35 try:
36 if torch.is_tensor(blocks[0]):
37 return torch.cat(blocks)
38 except:
39 pass
40
41 raise TypeError("%s datatype is not supported" % type(blocks[0]))
42
43
44def data_hstack(blocks: Sequence[modALinput]) -> modALinput:

Callers 4

ranked_batchFunction · 0.90
expected_error_reductionFunction · 0.90
_add_training_dataMethod · 0.90
add_rowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…