I want a submatrix from a n-dimensional matrix. Without knowing in advance the dimensionality of the matrix. So given:
import random
a = [10 for _ in range(0, random.randint(0,10))]
M = np.full(a, True)
# Now get the submatrix dynamically with block notation
# so something like:
# str = ["1:5" for _ in range(0, len(a))].join(",")
# N = eval("M[ " + str + "]")
I would like to know of a nice way to do this notation wise and also speed wise.
(The other answer supplied in Numpy extract submatrix does not directly solve the question, because the accepted answer, using .ix_
does not accept a slice.)