Outer product of two 512*512*300 matrices
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello everyone.
I wandering if any of you know how to do outer product for two matricess. The dimension of them are 512*512*300.
thank you.
댓글 수: 3
Alexander
2023년 10월 3일
Afaik the cross product is defined only for vectors. But I'm interested to know if there are other definitions.
John D'Errico
2023년 10월 3일
편집: John D'Errico
2023년 10월 3일
@Alexander Paul A CROSS product is defined for vectors. (And really, only for vectors of length 3 in classic terms. I do have a colleague who extended that definition to vectors of length 3, but it was of no real utiity that I recall.) In fact, cross is defined for arrays of vectors too, but there it applies to each vector in the array.
help cross
The thing is, the request was for an outer product.
답변 (1개)
John D'Errico
2023년 10월 3일
편집: John D'Errico
2023년 10월 3일
Since there has been no response to my request for clarification...
The request was for an outer product. An outer product is a very different animanl from a cross product. For example, the classical outer product between two vectors will create the element-wise product of every combinations of elements, thus a times table.
x = 1:5;
y = primes(15);
y'*x
Here, * does all the work for us. But we could also have used .* (or even bsxfun) as well.
y'.*x
The nice thing about .* or bsxfun is it will apply to higher dimensional arrays too. For example...
x = [1 2;3 4];
y = randi(9,[3,4])
Now we MIGHT decide to create an outer product here as:
z = x.*reshape(y,[1 1 size(y)])
size(z)
So every element of x scalar-multiplied by every element of y.
The problem is, if the arrays have size 512*512*300, then the outer product as I have shown it here would have size 512*512*300*512*512*300.
That is a pretty large array.
512*512*300*512*512*300
ans*8/1024^3
so approximately 46 million gigabytes of memory. You could cut that in half using singles of course. (Sigh. I hope nobody takes the idea about singles seriously.)
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!