Just a quick one. Is there a quicker (as in fewer characters) way to get the transpose of a matrix, other than just typing transpose(A)
?
there is A'
, which I think is identical
I thought that was the conjugate transpose? Similar to Matlab
'
is the conjugate transpose.
Yeah, you're right, sorry. Realized that I was using A'
like transpose(A)
...
There's a couple options. One would be to write:
julia> struct ᵀ end; Base.:(*)(A, ::Type{ᵀ}) = transpose(A)
julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> (A)ᵀ
2×2 transpose(::Matrix{Int64}) with eltype Int64:
1 3
2 4
Here's another option if you don't like unicode:
julia> struct T end; Base.:(^)(A, ::Type{T}) = transpose(A)
julia> A^T
2×2 transpose(::Matrix{Int64}) with eltype Int64:
1 3
2 4
Okay, I see. what's the \xxx
command for getting the T superscript?
It's \^T<TAB>
. BTW, you can always find these by pasting them into the help>
mode repl:
help?> ᵀ
"ᵀ" can be typed by \^T<tab>
search: ᵀ
No documentation found.
Summary
≡≡≡≡≡≡≡≡≡
struct ᵀ <: Any
Great. That's really helpful. Thanks
If you're on version 1.6 or later, another option is to locally shadow the '
variable in a let
block or whatever.
julia> let var"'" = transpose
A'
end
2×2 transpose(::Matrix{Int64}) with eltype Int64:
1 3
2 4
This can be handy when you have like a function body or something that has a few transposes in it and you want to be explicit about what means what
Happy to help!
Last updated: Nov 06 2024 at 04:40 UTC