假设我有一个2d NumPy ndarray,就像这样:
[[ 0, 1, 2, 3 ],
[ 4, 5, 6, 7 ],
[ 8, 9, 10, 11 ]]
Run Code Online (Sandbox Code Playgroud)
从概念上讲,我想要做的是:
For each row:
Transpose the row
Multiply the transposed row by a transformation matrix
Transpose the result
Store the result in the original ndarray, overwriting the original row data
Run Code Online (Sandbox Code Playgroud)
我有一个极其缓慢,强力的方法,在功能上实现了这一点:
import numpy as np
transform_matrix = np.matrix( /* 4x4 matrix setup clipped for brevity */ )
for i, row in enumerate( data ):
tr = row.reshape( …Run Code Online (Sandbox Code Playgroud)