Numpy operation | Sololearn: Learn to code for FREE!


Numpy operation

Given a nxn matrix, how can we find all possible combination of 3x3 matrix?

11/29/2018 12:11:15 PM

Bishu Giri

2 Answers

New Answer


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: