# 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:** 17

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [March 29, 2023, 6:31am UTC](https://discourse.julialang.org/t/outer-product-of-more-than-two-vectors/96310/17 "2023-03-29T06:31:19Z")

</div>

I was thinking about this after viewing the following video by Conor Hoekstra:

[![](https://global.discourse-cdn.com/julialang/original/3X/2/b/2b46fc4cd37dff595e491e9a8a642d23ce24babd.jpeg "APL vs BQN vs J vs Q vs NumPy vs Julia vs R") ](https://www.youtube.com/watch?v=8ynsN4nJxzU)

Julia gets dinged around minute 15 since broadcasting does not equate directly with an outer product in all circumstances. This gets explained further around minute 32 where he takes issues with `transpose` on `Vector`. See also this prior post:

> [@Should transpose of a Vector be a Matrix?](https://discourse.julialang.org/t/should-transpose-of-a-vector-be-a-matrix/87444):
>
> As Julia has a true 1D vector data type, shouldn’t the transpose of a Vector just be a Vector (essentially an identity operation)? See Conor Hoekstra’s comments in [APL vs BQN vs J vs Q vs NumPy vs Julia vs R - YouTube](https://youtu.be/8ynsN4nJxzU?t=1947) I assume this stems from MATLAB where a vector is actually a 2D array and that you can, of course, transpose. What are your thoughts about this?

ThIs thread clearly shows that a true outer product is also accessible in Julia.

Hoekstra’s original version without using `I` is as follows:

```julia
# check fo see if matrix is an X matrix
# where only the main diagonals are non-zero
function checkmatrix(grid)
    n = size(grid, 1)
    i = 1:n .== 1:n |> transpose
    min.(grid, 1) == max.(i, reverse(i, dims=1))
end

```

Using `Iterators.product`, `map`, and `allequal` we could do the following.

```julia
function checkmatrix2(grid)
    n = size(grid, 1)
    i = map(allequal, Iterators.product(1:n, 1:n))
    min.(grid, 1) == max.(i, reverse(i, dims=1))
end

```

---

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