You have several options:
foo[arg_?(VectorQ[#,NumericQ]&)]
foo[arg: {_?NumericQ ..}]
foo[arg: {__?NumericQ}]
For matrices or higher dimensional arrays, the equivalent of VectorQ
is MatrixQ
and ArrayQ
.
It's worth noting that VectorQ[..., NumericQ]
(and its relatives MatrixQ
and ArrayQ
) are highly optimized and will avoid unpacking packed arrays:
match = RandomReal[1, 10^6];
unpacked = Append[match, 1];
nonmatch = Append[match, "x"];
Table[
Timing[MatchQ[set, _?(VectorQ[#, NumericQ] &)]], {set, {match,
unpacked, nonmatch}}]
(* {{0.000016, True}, {0.003106, True}, {0.003184, False}} *)
Table[
Timing[MatchQ[set, _?(VectorQ[#, NumericQ[#] &] &)]], {set, {match,
unpacked, nonmatch}}]
(* {{0.402001, True}, {0.364469, True}, {0.362019, False}} *)
Table[
Timing[MatchQ[set, {_?NumericQ ..}]], {set, {match, unpacked,
nonmatch}}]
(* {{0.266730, True}, {0.231373, True}, {0.229849, False}} *)
Table[
Timing[MatchQ[set, {__?NumericQ}]], {set, {match, unpacked,
nonmatch}}]
(* {{0.226045, True}, {0.158696, True}, {0.160493, False}} *)
(VectorQ[#,NumericQ]&)
$\endgroup$p : {_?NumericQ ..}
$\endgroup$p:{__?NumericQ}
? $\endgroup$