小编use*_*880的帖子

如何有效地将矩阵变换应用于NumPy数组的每一行?

假设我有一个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)

python arrays numpy multidimensional-array

3
推荐指数
1
解决办法
8799
查看次数

标签 统计

arrays ×1

multidimensional-array ×1

numpy ×1

python ×1