VectorQ
Details
- A vector is a list whose elements can be considered scalars.
- A vector is also known as a flat list, a depth-1 array or a rank-1 array.
- Possible representations of a vector include: »
-
{…} or List[…] an ordinary list SparseArray[…] a sparse list TabularColumn[…], QuantityArray[…], SymmetrizedArray[…], etc. a structured list - The empty list {} is a zero-length vector. »
- Common values of test in VectorQ[expr,test] for use with numeric vectors include:
-
NumberQ test if expr is a vector of explicit numbers NumericQ test if expr is a vector of numeric expressions Positive test if expr is a vector of positive numbers RealValuedNumberQ test if expr is a vector of numbers with head Integer, Rational or Real RealValuedNumericQ test if expr is a vector of numeric expressions with real values - Structural tests commonly used include:
-
IntegerQ test if expr is a vector of integers PolynomialQ[#,x]& test if expr is a vector of polynomials in x QuantityQ test if expr is a vector of quantities StringQ test if expr is a vector of strings
Examples
open all close allBasic Examples (3)
Test whether an object is a vector:
VectorQ[{a, b, c}]This is not a vector because there is an element that is itself a list:
VectorQ[{1, {2, 3}}]And this is not a vector as x is not any sort of a list:
VectorQ[x]Use specific tests to restrict particular kinds of numbers:
VectorQ[{1, π, Sin[2]}, NumericQ]VectorQ[{1, π, Sin[2]}, NumberQ]Scope (7)
Many different heads can represent a vector:
VectorQ[SparseArray[{{1} -> a, {5} -> b}]]VectorQ[TabularColumn[{1, 2, 3}, "Integer8"]]VectorQ[Quantity[{1.3, 2.2, 3.3}, "Meters"]]Test for a vector with numeric entries:
VectorQ[{E, 1, π, 2, Sin[1], Cos[2]}, NumericQ]Test for a matrix with explicit numbers:
VectorQ[{E, 1, π, 2, Sin[1], Cos[2]}, NumberQ]Test for a vector of real-valued numeric quantities:
VectorQ[{1, Pi, Sin[1], Sqrt[2]}, RealValuedNumericQ]Faster test for explicit real-valued numbers:
VectorQ[{1, Pi, Sin[1], 3 / 4}, RealValuedNumberQ]Test for a vector of integers:
VectorQ[Range[10], IntegerQ]Test for a vector of numbers that are integers when rounded to two decimal places:
VectorQ[{1, 1.005, 1.997}, Abs[# - Round[#]] < 0.005&]VectorQ[{"a", "b", "c"}, StringQ]VectorQ[{"a", "b", x}, StringQ]Test for a vector of polynomials in x:
VectorQ[{1, x, 1 + x, x ^ 2 + 2x + 1}, PolynomialQ[#, x]&]VectorQ[{1, x, Sin[x], Exp[x]}, PolynomialQ[#, x]&]Generalize VectorQ using a test:
VectorQ[{{1}, {2, 3}}, ListQ]The tested expression is not a vector by the standard definition:
VectorQ[{{1}, {2, 3}}]Applications (1)
Define a function that only evaluates for vector arguments:
f[v_ ? VectorQ] := Module[{v1 = Take[v, {1, -1, 2}], v2 = Take[v, {2, -1, 2}], n},
n = Length[v2];
v2 = (v2 - PadRight[v1, n, v1] ^ 2);
v1 -= Range[Length[v1]];
v1.v1 + (Range[n]v2).v2];Numerically find the minimum of the functions with
components:
TableForm[Quiet[Table[FindMinimum[f[v], {v, RandomReal[1, n]}], {n, 1, 5}]]]Properties & Relations (5)
An empty list is considered a zero-length vector:
VectorQ[{}]VectorQ[expr] is equivalent to ArrayQ[expr,1]:
v = RandomReal[1, 3]{VectorQ[v], ArrayQ[v, 1]}VectorQ[expr,test] is equivalent to Array[expr,1,test]:
{VectorQ[v, MachineNumberQ], ArrayQ[v, 1, MachineNumberQ]}{VectorQ[v, IntegerQ], ArrayQ[v, 1, IntegerQ]}For a matrix m, VectorQ[m,VectorQ] gives True:
m = (| | |
| - | - |
| 1 | 2 |
| 3 | 4 |);
{MatrixQ[m], VectorQ[m, VectorQ]}The converse of this statement is False:
n = {{1, 2}, {3}};
{MatrixQ[n], VectorQ[n, VectorQ]}VectorQ effectively uses AllowedHeads"ListLike":
vec = SparseArray[{1, 2}];
expr = f[1, 2];{VectorQ[vec], VectorQ[expr]}{ArrayDepth[vec, AllowedHeads -> "ListLike"], ArrayDepth[expr, AllowedHeads -> "ListLike"]}{Dimensions[vec, AllowedHeads -> "ListLike"], Dimensions[expr, AllowedHeads -> "ListLike"]}A function equivalent to VectorQ for ordinary lists:
testf = MatchQ[#, List[args___ ? (Not[ListQ[#]]&)]]&vectors = {{}, {1, 2}, {1, {2}}, {{1, 2}}};TableForm[Table[{v, VectorQ[v], testf[v]}, {v, vectors}], TableDepth -> 2]See Also
Tech Notes
Related Guides
History
Introduced in 1988 (1.0) | Updated in 2003 (5.0)
Text
Wolfram Research (1988), VectorQ, Wolfram Language function, https://reference.wolfram.com/language/ref/VectorQ.html (updated 2003).
CMS
Wolfram Language. 1988. "VectorQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2003. https://reference.wolfram.com/language/ref/VectorQ.html.
APA
Wolfram Language. (1988). VectorQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/VectorQ.html
BibTeX
@misc{reference.wolfram_2026_vectorq, author="Wolfram Research", title="{VectorQ}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/VectorQ.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_vectorq, organization={Wolfram Research}, title={VectorQ}, year={2003}, url={https://reference.wolfram.com/language/ref/VectorQ.html}, note=[Accessed: 12-June-2026]}