MCPcopy Index your code
hub / github.com/python/cpython / transpose

Function transpose

Lib/test/test_buffer.py:348–361  ·  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

346 return ret
347
348def transpose(src, shape):
349 """Transpose flat item list that is regarded as a multi-dimensional
350 matrix defined by shape: dest...[k][j][i] = src[i][j][k]... """
351 if not shape:
352 return src
353 ndim = len(shape)
354 sstrides = strides_from_shape(ndim, shape, 1, 'C')
355 dstrides = strides_from_shape(ndim, shape[::-1], 1, 'C')
356 dest = [0] * len(src)
357 for ind in indices(shape):
358 fr = getindex(ndim, ind, sstrides)
359 to = getindex(ndim, ind[::-1], dstrides)
360 dest[to] = src[fr]
361 return dest
362
363def _flatten(lst):
364 """flatten list"""

Calls 3

strides_from_shapeFunction · 0.85
indicesFunction · 0.85
getindexFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…