フィルターのクリア

vectorization in tensors, how to add vector and matrix

5 ビュー (過去 30 日間)
Noya Linder
Noya Linder 2023 年 7 月 24 日
コメント済み: Voss 2023 年 8 月 15 日
Hi, say I have a 3X4 matrix M and a 1X100 row vector V. I want to add them (M+V) to create a 3D tensor T of 100X3X4. Meaning, I want to get a tensor consisting of the M matrix + V(index).
How should I go about that?
I previously asked this question but I just want the simplest possible way to do that
  1 件のコメント
Voss
Voss 2023 年 7 月 24 日
What was wrong with the answer you got when you asked this question before?

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

回答 (1 件)

Voss
Voss 2023 年 7 月 24 日
編集済み: Voss 2023 年 7 月 24 日
M = rand(3,4);
V = rand(1,100);
result = reshape(M,[1 size(M)]) + V(:);
size(result)
ans = 1×3
100 3 4
  1 件のコメント
Voss
Voss 2023 年 8 月 15 日
@Noya Linder: Did this answer work for you?

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

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by