I have this test implemented in my code, when I import a numeric matrix, which I thought would be bulletproof, but it's failing in this case:
In[]:= MatrixQ[{{}, {}}, NumericQ[#] && MatchQ[#, _Real] &]
Out[]= True
I don't get it.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI have this test implemented in my code, when I import a numeric matrix, which I thought would be bulletproof, but it's failing in this case:
In[]:= MatrixQ[{{}, {}}, NumericQ[#] && MatchQ[#, _Real] &]
Out[]= True
I don't get it.
Because there are no elements in your matrix. So there is no element which is not numeric and real.
MatrixQ[{{}, {}}, False &]
returns True
too.
So you have to exclude that case:
MatrixQ[##, NumericQ[#] && MatchQ[#, _Real] &] && !MatrixQ[##, False &] &
MatrixQ[{{}, {}}, False &]
somewhat more convincing. (Typo? If not, consider MatrixQ[{{1}, {1}}, True]
.) Or maybe MatrixQ[{{}, {}}, Print]
vs. MatrixQ[{{1}, {1}}, Print]
. In any case, +1.
$\endgroup$
– Michael E2
Oct 15 '16 at 21:40