フィルターのクリア

Outer product of two 512*512*300 matrices

3 ビュー (過去 30 日間)
Poorya
Poorya 2023 年 10 月 2 日
編集済み: Alexander 2023 年 10 月 3 日
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
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
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
CROSS Vector cross product. C = CROSS(A,B) returns the cross product of the vectors A and B. That is, C = A x B. A and B must be 3 element vectors. C = CROSS(A,B) returns the cross product of A and B along the first dimension of length 3. C = CROSS(A,B,DIM), where A and B are N-D arrays, returns the cross product of vectors in the dimension DIM of A and B. A and B must have the same size, and both SIZE(A,DIM) and SIZE(B,DIM) must be 3. Class support for inputs A,B: float: double, single See also DOT. Documentation for cross doc cross Other uses of cross distributed/cross
The thing is, the request was for an outer product.

サインインしてコメントする。

回答 (1 件)

John D'Errico
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
ans = 6×5
2 4 6 8 10 3 6 9 12 15 5 10 15 20 25 7 14 21 28 35 11 22 33 44 55 13 26 39 52 65
Here, * does all the work for us. But we could also have used .* (or even bsxfun) as well.
y'.*x
ans = 6×5
2 4 6 8 10 3 6 9 12 15 5 10 15 20 25 7 14 21 28 35 11 22 33 44 55 13 26 39 52 65
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])
y = 3×4
3 8 2 7 5 8 7 8 9 7 6 8
Now we MIGHT decide to create an outer product here as:
z = x.*reshape(y,[1 1 size(y)])
z =
z(:,:,1,1) = 3 6 9 12 z(:,:,2,1) = 5 10 15 20 z(:,:,3,1) = 9 18 27 36 z(:,:,1,2) = 8 16 24 32 z(:,:,2,2) = 8 16 24 32 z(:,:,3,2) = 7 14 21 28 z(:,:,1,3) = 2 4 6 8 z(:,:,2,3) = 7 14 21 28 z(:,:,3,3) = 6 12 18 24 z(:,:,1,4) = 7 14 21 28 z(:,:,2,4) = 8 16 24 32 z(:,:,3,4) = 8 16 24 32
size(z)
ans = 1×4
2 2 3 4
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 = 6.1848e+15
ans*8/1024^3
ans = 46080000
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 件のコメント
Alexander
Alexander 2023 年 10 月 3 日
編集済み: Alexander 2023 年 10 月 3 日
Thank you for this clear explanation. In German "Kreuzprodukt" and "Äußeres Produkt" is equivalent. I'm now investigating what an english "Outer Product" in german language is. The english wikipedia is more precise, and I will investigate this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by