整数数组索引的块状块矩阵分配

时间:2018-09-16 20:21:46

标签: python numpy

是否有一种优雅的方式(没有循环)通过numpy索引进行这种分配?

import numpy as np

m = 3
n = 5
small_matrix = np.random.randn(m, n)
big_matrix = np.zeros((100, 100))
row_indices = [3, 16, 9]
col_indices = [31, 45, 69, 71, 83]

for i in range(m):
    for j in range(n):
        big_matrix[row_indices[i], col_indices[j]] = small_matrix[i, j]

0 个答案:

没有答案