1

Is there an elegant way (without loops) to do this kind of assignment with numpy indexing?

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]
janismac
  • 106
  • 1
  • 6

0 Answers0