# How to do sparse row vector\*matrix?

**URL:** https://discourse.julialang.org/t/how-to-do-sparse-row-vector-matrix/121166
**Category:** New to Julia
**Created:** [October 10, 2024, 9:01pm UTC](https://discourse.julialang.org/t/how-to-do-sparse-row-vector-matrix/121166 "2024-10-10T21:01:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![happyxie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/happyxie/32/212425_2.png) [@happyxie](https://discourse.julialang.org/u/happyxie)
#### Post date: [October 10, 2024, 9:01pm UTC](https://discourse.julialang.org/t/how-to-do-sparse-row-vector-matrix/121166/1 "2024-10-10T21:01:21Z")

</div>

I am trying to do a row vector times a matrix but it give an adjoint type instead of a row vector? should I do (A’A[1,:])'? I need the results to be a vector so I can continue other calculation.  
Thanks.

A=sparse([1 2;3 4])  
A[1,:]'A

#1×2 adjoint(::SparseVector{Int64, Int64}) with eltype Int64

---

<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: [October 10, 2024, 9:25pm UTC](https://discourse.julialang.org/t/how-to-do-sparse-row-vector-matrix/121166/2 "2024-10-10T21:25:39Z")

</div>

> [@happyxie](#):
>
> adjoint type instead of a row vector?

That is a row vector. [https://www.youtube.com/watch?v=C2RO34b\_oPM](https://www.youtube.com/watch?v=C2RO34b_oPM)

---

<div class="post-metadata">

### Author: ![happyxie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/happyxie/32/212425_2.png) [@happyxie](https://discourse.julialang.org/u/happyxie)
#### Post date: [October 10, 2024, 9:37pm UTC](https://discourse.julialang.org/t/how-to-do-sparse-row-vector-matrix/121166/3 "2024-10-10T21:37:00Z")

</div>

Thanks. But I just did a type conversion for it like:  
sparsevec(A[1,:]'A)

This solved my problem.

---

<div class="post-metadata">

### Author: ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)
#### Post date: [October 11, 2024, 1:43pm UTC](https://discourse.julialang.org/t/how-to-do-sparse-row-vector-matrix/121166/4 "2024-10-11T13:43:41Z")

</div>

A little more direct (and performant) is either of

```julia-repl
julia> (A[1,:]' * A)'
2-element SparseVector{Int64, Int64} with 2 stored entries:
  [1] = 7
  [2] = 10

julia> A' * A[1,:]
2-element SparseVector{Int64, Int64} with 2 stored entries:
  [1] = 7
  [2] = 10

```

For real numbers this is fine, but if your numbers are complex then you should be careful about the conjugation of the result.
