Multiple a single tensor with mulitple tensor element wise

username: KURUVILLA_ABRAHAM
cooked: <p>Hi Team,</p>
<h1>
<a name="below-is-my-query-1" class="anchor" href="#below-is-my-query-1"></a>Below is my query</h1>
<p>image = torch.randn(1,256,16,16)</p>
<p><span class="hashtag">#Target</span> color blue<br>
Target_color_blue = torch.zeros(1, 1, 3, dtype=torch.float)<br>
Target_color_blue[:,:,2] = 255</p>
<p><span class="hashtag">#Target</span> color red<br>
Target_color_red = torch.zeros(1, 1, 3, dtype=torch.float)<br>
Target_color_red[:,:,0] = 255</p>
<p><span class="hashtag">#Target</span> color green<br>
Target_color_green = torch.zeros(1, 1, 3, dtype=torch.float)<br>
Target_color_green[:,:,1] = 128</p>
<p>Target_color_list = [Target_color_blue,Target_color_red,Target_color_green]<br>
<span class="hashtag">#Stacking</span> both red and blue tensors<br>
Target_colors = torch.stack(Target_color_list)</p>
<p>Want to multiply</p>
<h1>
<a name="image-target_colors-2" class="anchor" href="#image-target_colors-2"></a>image * Target_colors</h1>
<h1>
<a name="target-color-shape-is-torchsize3-1-1-3-while-image-shape-is-12561616-3" class="anchor" href="#target-color-shape-is-torchsize3-1-1-3-while-image-shape-is-12561616-3"></a>Target color shape is torch.Size([3, 1, 1, 3]) while image shape is (1,256,16,16)</h1>
<p>So final shape should be of length 3</p>

username: anantguptadbl
cooked: <p><a class="mention" href="/u/kuruvilla_abraham">@KURUVILLA_ABRAHAM</a> your image is of size (1,256,16,16)</p>
<p>What do the individual dimensions denote</p>
<ul>
<li>
<p>Which one denotes channel : If the channel is 256 or 16 how do we select the channel for multiplication with the target color</p>
</li>
<li>
<p>Is the size of the image 16 height * 16 width?</p>
</li>
<li>
<p>Just curious to know, what are you trying to achieve through this</p>
</li>
</ul>
<p>Can you provide a sample output.</p>

username: KURUVILLA_ABRAHAM
cooked: <p>Hello anant ,</p>
<p>(1,256,16,16) - represent (batch * channel* height * width)<br>
Target colors in this case are 3 - I am using below code to produce it</p>
<p><span class="hashtag">#Target</span> color blue<br>
Target_color_blue = torch.zeros(1, 1, 3, dtype=torch.float)<br>
Target_color_blue[:,:,2] = 255</p>
<p><span class="hashtag">#Target</span> color red<br>
Target_color_red = torch.zeros(1, 1, 3, dtype=torch.float)<br>
Target_color_red[:,:,0] = 255</p>
<p><span class="hashtag">#Target</span> color green<br>
Target_color_green = torch.zeros(1, 1, 3, dtype=torch.float)<br>
Target_color_green[:,:,1] = 128</p>
<p>Target_color_list = [Target_color_blue,Target_color_red,Target_color_green]<br>
<span class="hashtag">#Stacking</span> both red and blue tensors<br>
Target_colors = torch.stack(Target_color_list)</p>
<p>now my output should be -</p>
<h1>
<a name="all-colors-mutiplied-with-image1-1" class="anchor" href="#all-colors-mutiplied-with-image1-1"></a>all colors mutiplied with image1</h1>
<p>image1<em>Target_color1<br>
image1</em>Target_color2<br>
image1*Target_color3</p>
<h1>
<a name="all-colors-mutiplied-with-image2-2" class="anchor" href="#all-colors-mutiplied-with-image2-2"></a>all colors mutiplied with image2</h1>
<p>image2<em>Target_color1<br>
image2</em>Target_color2<br>
image2*Target_color3</p>

username: anantguptadbl
cooked: <p><a class="mention" href="/u/kuruvilla_abraham">@KURUVILLA_ABRAHAM</a> in that case there is mismatch between the number of channels in the Target_colors and the channels in image</p>
<p>Taget_colors have 3 channels and image has 256 channels. How will we able to multiply?</p>

username: KURUVILLA_ABRAHAM
cooked: <p>Ok in that case if I increase the color dimension to 256 will it impact my color</p>

username: anantguptadbl
cooked: <p>Absolutely. 3 Channels refer to RGB<br>
If you change to 256 you will have to come up with your own understanding of what each channel means, as it is a mathematical representation</p>