# Pinv of matrix transpose?

**URL:** https://discourse.julialang.org/t/pinv-of-matrix-transpose/22704
**Category:** General Usage
**Tags:** linearalgebra
**Created:** [April 3, 2019, 3:23pm UTC](https://discourse.julialang.org/t/pinv-of-matrix-transpose/22704 "2019-04-03T15:23:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tawheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tawheeler/32/17657_2.png) [@tawheeler](https://discourse.julialang.org/u/tawheeler)
#### Post date: [April 3, 2019, 3:23pm UTC](https://discourse.julialang.org/t/pinv-of-matrix-transpose/22704/1 "2019-04-03T15:23:32Z")

</div>

I tried to use `pinv` on a transposed matrix and it surprisingly err’d out. What is the correct way to go about this?

```julia
julia> using LinearAlgebra

julia> A = rand(3,2)
3×2 Array{Float64,2}:
0.384492 0.512766
0.894825 0.866387
0.821847 0.945962

julia> pinv(A)
2×3 Array{Float64,2}:
-4.39446 5.15053 -2.33521
 4.29807 -4.26865 2.63689

julia> pinv(A')
ERROR: MethodError: no method matching pinv(::Adjoint{Float64,Array{Float64,2}})

julia> pinv(transpose(A))
ERROR: MethodError: no method matching pinv(::Transpose{Float64,Array{Float64,2}})

```

---

<div class="post-metadata">

### Author: ![under-Peter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/under-peter/32/3626_2.png) [@under-Peter](https://discourse.julialang.org/u/under-Peter)
#### Post date: [April 3, 2019, 3:28pm UTC](https://discourse.julialang.org/t/pinv-of-matrix-transpose/22704/2 "2019-04-03T15:28:19Z")

</div>

What version of Julia are you using? I can’t reproduce with 1.1.0.

Anyway you can convert a `Adjoint` or `Transpose` matrix type to a regular `Array` using `collect`.  
So try

```julia
julia> pinv(collect(A'))

```

(maybe there’s something else wrong, there should be pinv for `Transpose`’d arrays)

---

<div class="post-metadata">

### Author: ![tawheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tawheeler/32/17657_2.png) [@tawheeler](https://discourse.julialang.org/u/tawheeler)
#### Post date: [April 3, 2019, 3:29pm UTC](https://discourse.julialang.org/t/pinv-of-matrix-transpose/22704/3 "2019-04-03T15:29:15Z")

</div>

Thanks! I am on julia 1.0.1. I’ll try upgrading and see whether that fixes it.  
Collecting works in the mean time too!

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [April 3, 2019, 3:42pm UTC](https://discourse.julialang.org/t/pinv-of-matrix-transpose/22704/4 "2019-04-03T15:42:45Z")

</div>

You should use `copy` instead of `collect` for materializing lazy adjoints/transposes.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [April 3, 2019, 4:00pm UTC](https://discourse.julialang.org/t/pinv-of-matrix-transpose/22704/5 "2019-04-03T16:00:46Z")

</div>

> [@under-Peter](#):
>
> What version of Julia are you using? I can’t reproduce with 1.1.0.

It was fixed in

> <https://github.com/JuliaLang/julia/pull/29837>
>
> Fixes #29723

---

<div class="post-metadata">

### Author: ![tawheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tawheeler/32/17657_2.png) [@tawheeler](https://discourse.julialang.org/u/tawheeler)
#### Post date: [April 6, 2019, 2:13am UTC](https://discourse.julialang.org/t/pinv-of-matrix-transpose/22704/6 "2019-04-06T02:13:10Z")

</div>

Julia 1.1.0 did fix my issue!
