# Outer product of more than two vectors

**URL:** <https://discourse.julialang.org/t/outer-product-of-more-than-two-vectors/96310>\
**Category:** General Usage\
**Tags:** question, performance, linearalgebra\
**Created:** [March 19, 2023, 3:48pm UTC](https://discourse.julialang.org/t/outer-product-of-more-than-two-vectors/96310 "2023-03-19T15:48:10Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [March 19, 2023, 4:13pm UTC](https://discourse.julialang.org/t/outer-product-of-more-than-two-vectors/96310/5 "2023-03-19T16:13:48Z")

</div>

Got it 🙂

```julia
julia> outer_product2(vs) = .*([reshape(vs[d], (ntuple(Returns(1), d-1)..., :)) for d in 1:length(vs)]... )

julia> @benchmark outer_product($vs)
BenchmarkTools.Trial: 10000 samples with 5 evaluations.
 Range (min … max): 6.045 μs … 1.440 ms ┊ GC (min … max): 0.00% … 98.98%
 Time (median): 6.857 μs ┊ GC (median): 0.00%
 Time (mean ± σ): 7.907 μs ± 31.443 μs ┊ GC (mean ± σ): 8.84% ± 2.21%

   ▅▃▄▃▁█                                                     
  ███████▇▅▄▃▃▃▂▃▂▃▂▄▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▃
  6.04 μs Histogram: frequency by time 15.6 μs <

 Memory estimate: 5.11 KiB, allocs estimate: 135.

julia> @benchmark outer_product2($vs)
BenchmarkTools.Trial: 10000 samples with 10 evaluations.
 Range (min … max): 1.632 μs … 591.462 μs ┊ GC (min … max): 0.00% … 99.03%
 Time (median): 1.880 μs ┊ GC (median): 0.00%
 Time (mean ± σ): 2.032 μs ± 5.930 μs ┊ GC (mean ± σ): 2.88% ± 0.99%

     ██▃▁ ▄▂ ▂ ▁▂                                              
  ▂▄▇████▇████████▆█▆▄▃▄▃▃▃▃▃▃▄▄▂▂▂▂▂▂▂▂▂▂▂▃▄▃▂▂▂▃▂▂▁▁▁▁▁▂▂▁▁ ▃
  1.63 μs Histogram: frequency by time 2.82 μs <

 Memory estimate: 752 bytes, allocs estimate: 15.

```

thanks 🙂

---

_[View the full topic](https://discourse.julialang.org/t/outer-product-of-more-than-two-vectors/96310)._
