0

Edited since my last question was a duplicate, but I'm struggling with this as well. I'm currently working with a matrix and can easily find the largest element with

M[M != 1].max()

However, I'm interested in getting the N largest elements and can't find an easy way to do this with matrices. Is there an efficient solution?

4
  • 4
    Hi @planner15 - as per the link, np.where(M == M[M != 0].min()) should return the row and column indices corresponding to the minimum element. Commented Apr 17, 2015 at 16:20
  • The revised question is still a duplicate, see this question, and this question for finding the indices. Commented Apr 17, 2015 at 17:59
  • @moarningsun I saw those, but those are for arrays. Would they still apply to matrices? Commented Apr 17, 2015 at 18:22
  • @planner15: The same basic idea applies, but you may need to do some small syntactical changes. Commented Apr 17, 2015 at 19:04

1 Answer 1

0

Yes there is a where method which takes a condition as one of the parameter ,

minimum = M[M != 0].min()

print numpy.where(M==minimum)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.