I have a very simple question, and I'm sure there is a way to do this but I cannot find it:

if I want to create a function that's defined only for matrices, I can do it like this:


but what if I want to define a function which is defined only for matrices whose entries are numbers? I would like to combine MatrixQ with NumberQ for its matrix elements but I'm not sure how to make this work.


1 Answer 1


I was going for a syntactic pattern thing, but actually the two-argument form of MatrixQ should work here:


MatrixQ[expr,test] gives True only if test yields True when applied to each of the matrix elements in expr.

  • $\begingroup$ I had tried something like this, but without the parenthesis. This works, thanks! $\endgroup$
    – bnado
    Apr 29, 2016 at 12:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.