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

Function chunks_from_arrays

dask/array/core.py:5423–5456  ·  view source on GitHub ↗

Chunks tuple from nested list of arrays >>> x = np.array([1, 2]) >>> chunks_from_arrays([x, x]) ((2, 2),) >>> x = np.array([[1, 2]]) >>> chunks_from_arrays([[x], [x]]) ((1, 1), (2,)) >>> x = np.array([[1, 2]]) >>> chunks_from_arrays([[x, x]]) ((1,), (2, 2))

(arrays)

Source from the content-addressed store, hash-verified

5421
5422
5423def chunks_from_arrays(arrays):
5424 """Chunks tuple from nested list of arrays
5425
5426 >>> x = np.array([1, 2])
5427 >>> chunks_from_arrays([x, x])
5428 ((2, 2),)
5429
5430 >>> x = np.array([[1, 2]])
5431 >>> chunks_from_arrays([[x], [x]])
5432 ((1, 1), (2,))
5433
5434 >>> x = np.array([[1, 2]])
5435 >>> chunks_from_arrays([[x, x]])
5436 ((1,), (2, 2))
5437
5438 >>> chunks_from_arrays([1, 1])
5439 ((1, 1),)
5440 """
5441 if not arrays:
5442 return ()
5443 result = []
5444 dim = 0
5445
5446 def shape(x):
5447 try:
5448 return x.shape or (1,)
5449 except AttributeError:
5450 return (1,)
5451
5452 while isinstance(arrays, (list, tuple)):
5453 result.append(tuple(shape(deepfirst(a))[dim] for a in arrays))
5454 arrays = arrays[0]
5455 dim += 1
5456 return tuple(result)
5457
5458
5459def deepfirst(seq):

Callers 1

concatenate3Function · 0.85

Calls 2

deepfirstFunction · 0.85
shapeFunction · 0.70

Tested by

no test coverage detected