# Question about A' and Transpose(A)

``````julia> A = [1 + 0.2im, 2 + 0.6im]
2-element Vector{ComplexF64}:
1.0 + 0.2im
2.0 + 0.6im

julia> A'
1.0-0.2im  2.0-0.6im

julia> Transpose(A)
1×2 transpose(::Vector{ComplexF64}) with eltype ComplexF64:
1.0+0.2im  2.0+0.6im

julia> A' == Transpose(A)
false
``````

What’s wrong with this?Why A’ != Transpose(A)?

``````help?> '
search: ' ''

A'

Lazy adjoint (conjugate transposition). Note that adjoint is applied recursively to elements.
``````
1 Like

`A'` indicates the adjoint of `A`, i.e. it gives you transposition + complex conjugation. For real matrices, you will notice that `A' == transpose(A)`.

@carstenbauer @jling Thank you very much for your kindly reply.This my first time to use Julia.

Let me welcome you to the community then!

Note that it’s usually preferable to use the function `transpose`, not the type constructor `Transpose`. The main reason is that `transpose` is aware that transposes undo themselves, so `transpose(transpose(A))` just returns `A`. In contrast, `Transpose` always piles on another layer of the `Transpose` wrapper type:

``````julia> Transpose(Transpose(A))
2×1 transpose(transpose(::Vector{ComplexF64})) with eltype ComplexF64:
1.0 + 0.2im
2.0 + 0.6im

julia> transpose(transpose(A))
2-element Vector{ComplexF64}:
1.0 + 0.2im
2.0 + 0.6im

julia> transpose(transpose(A)) === A
true
``````

The same goes for `adjoint` vs. `Adjoint`.

2 Likes

Thanks very much. I have another question. How can I transform the Matlab code into Julia.

This is the Matlab code. a is a vector and b is a number.

``````x(a <= 0 | b <= 0) = -1
``````

I try to write the corresponding Julia code.

``````julia> x = ones(3,1)
3×1 Matrix{Float64}:
1.0
1.0
1.0

julia> a = [1, -1, -0.02]
3-element Vector{Float64}:
1.0
-1.0
-0.02

julia> b = 0.2
0.2

julia> if b <= 0 x .= -1 end

julia> x[a .<= 0] .= -1
2-element view(::Vector{Float64}, [2, 3]) with eltype Float64:
-1.0
-1.0

julia> x
3×1 Matrix{Float64}:
1.0
-1.0
-1.0
``````

But I don’t think my code is the simpliest. I think Julia should have better code to do this.Any suggestions about this?

Does this do what you want?

``````julia> x[(a .<= 0) .| (b .<= 0)] .= -1
2-element view(::Vector{Float64}, [2, 3]) with eltype Float64:
-1.0
-1.0

julia> x
3×1 Matrix{Float64}:
1.0
-1.0
-1.0
``````

Yes, this is what I want. Thanks a lot.

I also try to use `@.`

``````@. x[(a <= 0) | (b <= 0)] = -1
``````
1 Like