DimensionMismatch
DimensionMismatch([msg])
The objects called do not have matching dimensionality.
Optional argument msg is a descriptive error string.
Examples
-
Basic usage:
julia> a = [1, 2, 3]; julia> b = [4, 5]; julia> c = [6, 7, 8]; julia> DimensionMismatch(a, b) ERROR: DimensionMismatch: arrays could not be broadcast to a common size julia> DimensionMismatch(a, c) ERROR: DimensionMismatch: arrays could not be broadcast to a common sizeIn these examples,
DimensionMismatchis used to indicate that the arraysaandb, andaandc, respectively, cannot be broadcast to a common size due to a dimension mismatch. -
Custom error message:
julia> x = [1, 2]; julia> y = [3, 4, 5]; julia> DimensionMismatch("Custom error message: Arrays do not have matching dimensions.", x, y) ERROR: DimensionMismatch: Custom error message: Arrays do not have matching dimensions.Here,
DimensionMismatchis used with a custom error message provided as the argumentmsg. It helps provide more descriptive information about the dimension mismatch between the arraysxandy.
Common mistake example:
julia> a = [1, 2, 3];
julia> b = [4, 5, 6];
julia> DimensionMismatch(a, b, "Mismatch between arrays")
ERROR: MethodError: no method matching DimensionMismatch(::Array{Int64,1}, ::Array{Int64,1}, ::String)
In this example, the third argument provided is a string, which is not a valid argument for DimensionMismatch. The third argument should be an optional descriptive error string, but it is not applicable in this context. Make sure to provide the correct arguments to DimensionMismatch.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.