MCPcopy Create free account
hub / github.com/dask/dask / concatenate3

Function concatenate3

dask/array/core.py:5625–5692  ·  view source on GitHub ↗

Recursive np.concatenate Input should be a nested list of numpy arrays arranged in the order they should appear in the array itself. Each array should have the same number of dimensions as the desired output and the nesting of the lists. >>> x = np.array([[1, 2]]) >>> concaten

(arrays)

Source from the content-addressed store, hash-verified

5623
5624
5625def concatenate3(arrays):
5626 """Recursive np.concatenate
5627
5628 Input should be a nested list of numpy arrays arranged in the order they
5629 should appear in the array itself. Each array should have the same number
5630 of dimensions as the desired output and the nesting of the lists.
5631
5632 >>> x = np.array([[1, 2]])
5633 >>> concatenate3([[x, x, x], [x, x, x]])
5634 array([[1, 2, 1, 2, 1, 2],
5635 [1, 2, 1, 2, 1, 2]])
5636
5637 >>> concatenate3([[x, x], [x, x], [x, x]])
5638 array([[1, 2, 1, 2],
5639 [1, 2, 1, 2],
5640 [1, 2, 1, 2]])
5641 """
5642 # We need this as __array_function__ may not exist on older NumPy versions.
5643 # And to reduce verbosity.
5644 NDARRAY_ARRAY_FUNCTION = getattr(np.ndarray, "__array_function__", None)
5645
5646 arrays = concrete(arrays)
5647 if not arrays or all(el is None for el in flatten(arrays)):
5648 return np.empty(0)
5649
5650 advanced = max(
5651 core.flatten(arrays, container=(list, tuple)),
5652 key=lambda x: getattr(x, "__array_priority__", 0),
5653 )
5654
5655 if not all(
5656 NDARRAY_ARRAY_FUNCTION
5657 is getattr(type(arr), "__array_function__", NDARRAY_ARRAY_FUNCTION)
5658 for arr in core.flatten(arrays, container=(list, tuple))
5659 ):
5660 try:
5661 x = unpack_singleton(arrays)
5662 return _concatenate2(arrays, axes=tuple(range(x.ndim)))
5663 except TypeError:
5664 pass
5665
5666 if concatenate_lookup.dispatch(type(advanced)) is not np.concatenate:
5667 x = unpack_singleton(arrays)
5668 return _concatenate2(arrays, axes=list(range(x.ndim)))
5669
5670 ndim = ndimlist(arrays)
5671 if not ndim:
5672 return arrays
5673 chunks = chunks_from_arrays(arrays)
5674 shape = tuple(map(sum, chunks))
5675
5676 def dtype(x):
5677 try:
5678 return x.dtype
5679 except AttributeError:
5680 return type(x)
5681
5682 result = np.empty(shape=shape, dtype=dtype(deepfirst(arrays)))

Callers 8

test_chunked_dot_productFunction · 0.90
test_concatenate3_2Function · 0.90
finalizeFunction · 0.85
concatenate_shapedFunction · 0.85
concatenate_axesFunction · 0.85

Calls 14

concreteFunction · 0.90
allFunction · 0.90
flattenFunction · 0.90
maxFunction · 0.90
ndimlistFunction · 0.90
unpack_singletonFunction · 0.85
_concatenate2Function · 0.85
chunks_from_arraysFunction · 0.85
deepfirstFunction · 0.85
slices_from_chunksFunction · 0.85
flattenMethod · 0.80
dtypeFunction · 0.70