transpose!
transpose!(dest,src)
Transpose array src
and store the result in the preallocated array dest
, which should have a size corresponding to (size(src,2),size(src,1))
. No in-place transposition is supported and unexpected results will happen if src
and dest
have overlapping memory regions.
Examples
-
Transpose a matrix to a preallocated array:
julia> src = [1 2 3; 4 5 6]; julia> dest = zeros(Int, (size(src, 2), size(src, 1))); julia> transpose!(dest, src) 3×2 Array{Int64,2}: 1 4 2 5 3 6
This example transposes the matrix
src
and stores the result in the preallocated arraydest
. -
Transpose a 1x1 matrix:
julia> src = [42]; julia> dest = zeros(Int, (size(src, 2), size(src, 1))); julia> transpose!(dest, src) 1×1 Array{Int64,2}: 42
It transposes a 1x1 matrix and stores the result in the preallocated array.
- Ensure non-overlapping memory regions:
julia> src = [1 2; 3 4]; julia> dest = [0 0; 0 0]; julia> transpose!(dest, src) 2×2 Array{Int64,2}: 1 3 2 4
It is important to ensure that
src
anddest
do not have overlapping memory regions, as it may lead to unexpected results.
Common mistake example:
julia> src = [1 2 3; 4 5 6];
julia> dest = zeros(Int, (2, 3));
julia> transpose!(dest, src)
ERROR: DimensionMismatch("output dimensions must be compatible with input dimensions")
In this example, the size of the preallocated dest
array does not match the expected size for the transpose operation. Ensure that dest
has dimensions corresponding to (size(src, 2), size(src, 1))
to avoid such errors.
See Also
Array, broadcast, cat, combinations, conj!, digits!, fieldnames, fill, fill!, last, length, maximum, minimum, ones, parent, parentindexes, partitions, permutations, pointer, pointer_to_array, promote_shape, rand!, reshape, scale, similar, sum, sum_kbn, takebuf_array, transpose!, vec, zeros,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.