0

I want to subset a d = (d1,...,dn)-shaped numpy array A to get only the r = (r1,...,rn) first principal minor, i.e all values A[i1,...,in] such that ij < rj. The resulting array has shape r, of course.

How can i do that ? I tried A[:r] but of course it did not work :). The right way would be A[:r1,...,:rn], but len(A.shape) is unknown, so i cant write all subsetting one by one.

Do you have an idea on how i could get this submatrix ?

1 Answer 1

2

You can use

A[tuple([slice(None, i) for i in r])]
Sign up to request clarification or add additional context in comments.

2 Comments

Perfec, thanks. Did not know about the slice() function !
The inner pair of square brackets are unnecessary, but otherwise looks good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.