# Resulting type from multiplication of a sparse and full matrix

**URL:** <https://discourse.julialang.org/t/resulting-type-from-multiplication-of-a-sparse-and-full-matrix/21584>\
**Category:** General Usage\
**Created:** [March 7, 2019, 4:08pm UTC](https://discourse.julialang.org/t/resulting-type-from-multiplication-of-a-sparse-and-full-matrix/21584 "2019-03-07T16:08:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalekj](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dalekj](https://discourse.julialang.org/u/dalekj)\
**Post date:** [March 7, 2019, 4:08pm UTC](https://discourse.julialang.org/t/resulting-type-from-multiplication-of-a-sparse-and-full-matrix/21584/1 "2019-03-07T16:08:21Z")

</div>

Given a full matrix `A` and a sparse matrix `B`, matrix multiplication gives a different resulting type (either full or sparse) depending on the order of multiplication and whether or not a transpose is involved:

```julia
julia> A = randn(5,5);

julia> B = sprand(5,5,.1);

julia> typeof(A*B)
Array{Float64,2}

julia> typeof(B*A)
Array{Float64,2}

julia> typeof(A'*B)
SparseMatrixCSC{Float64,Int64}

julia> typeof(A*B')
SparseMatrixCSC{Float64,Int64}

julia> typeof(B*A')
Array{Float64,2}

julia> typeof(B'*A)
Array{Float64,2}

```

What is the logic behind these resulting types?
