MCPcopy Index your code
hub / github.com/RustPython/RustPython / transpose

Function transpose

Lib/test/test_buffer.py:336–349  ·  view source on GitHub ↗

Transpose flat item list that is regarded as a multi-dimensional matrix defined by shape: dest...[k][j][i] = src[i][j][k]...

(src, shape)

Source from the content-addressed store, hash-verified

334 return ret
335
336def transpose(src, shape):
337 """Transpose flat item list that is regarded as a multi-dimensional
338 matrix defined by shape: dest...[k][j][i] = src[i][j][k]... """
339 if not shape:
340 return src
341 ndim = len(shape)
342 sstrides = strides_from_shape(ndim, shape, 1, 'C')
343 dstrides = strides_from_shape(ndim, shape[::-1], 1, 'C')
344 dest = [0] * len(src)
345 for ind in indices(shape):
346 fr = getindex(ndim, ind, sstrides)
347 to = getindex(ndim, ind[::-1], dstrides)
348 dest[to] = src[fr]
349 return dest
350
351def _flatten(lst):
352 """flatten list"""

Calls 4

lenFunction · 0.85
strides_from_shapeFunction · 0.85
indicesFunction · 0.85
getindexFunction · 0.85

Tested by

no test coverage detected