+ 2
Numpy operation
Given a nxn matrix, how can we find all possible combination of 3x3 matrix?
2 Respostas
+ 3
I like to use numpy.ix_ to extract submatrices.
import numpy as np
from itertools import combinations
n = 4
mat = np.arange(n**2).reshape((n, n))
print("Original matrix:\n", mat)
print("\n3x3 submatrices:")
for r in combinations(range(n), 3):
for c in combinations(range(n), 3):
print(mat[np.ix_(r, c)])
print()
Reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.ix_.html
0
4