Permute axes of nested list >>> transposelist([[1,1,1],[1,1,1]], [2,1]) [[[1, 1], [1, 1], [1, 1]]] >>> transposelist([[1,1,1],[1,1,1]], [2,1], extradims=1) [[[[1], [1]], [[1], [1]], [[1], [1]]]]
(arrays, axes, extradims=0)
| 5482 | |
| 5483 | |
| 5484 | def transposelist(arrays, axes, extradims=0): |
| 5485 | """Permute axes of nested list |
| 5486 | |
| 5487 | >>> transposelist([[1,1,1],[1,1,1]], [2,1]) |
| 5488 | [[[1, 1], [1, 1], [1, 1]]] |
| 5489 | |
| 5490 | >>> transposelist([[1,1,1],[1,1,1]], [2,1], extradims=1) |
| 5491 | [[[[1], [1]], [[1], [1]], [[1], [1]]]] |
| 5492 | """ |
| 5493 | if len(axes) != ndimlist(arrays): |
| 5494 | raise ValueError("Length of axes should equal depth of nested arrays") |
| 5495 | if extradims < 0: |
| 5496 | raise ValueError("`newdims` should be positive") |
| 5497 | if len(axes) > len(set(axes)): |
| 5498 | raise ValueError("`axes` should be unique") |
| 5499 | |
| 5500 | ndim = max(axes) + 1 |
| 5501 | shape = shapelist(arrays) |
| 5502 | newshape = [ |
| 5503 | shape[axes.index(i)] if i in axes else 1 for i in range(ndim + extradims) |
| 5504 | ] |
| 5505 | |
| 5506 | result = list(core.flatten(arrays)) |
| 5507 | return reshapelist(newshape, result) |
| 5508 | |
| 5509 | |
| 5510 | def stack(seq, axis=0, allow_unknown_chunksizes=False): |
no test coverage detected
searching dependent graphs…