l have the following input x=dim(16,16,3) that l would like to pass tonn.Linear()

cl = nn.Linear(16,32,3)

when l make x=cl(x) l get the following error :
***** RuntimeError: size mismatch at /opt/conda/conda-bld/pytorch_1518243271935/work/torch/lib/THC/generic/THCTensorMathBlas.cu:247**

From the docs :
“Input: (N,∗,in_features) where * means any number of additional dimensions.
Output: (N,∗,out_features) where all but the last dimension are the same shape as the input.”

So with nn.Linear, you can apply a transformation on the last dimension of you input.

but according to documentation Output: (N,∗,out_features) is equivalent to cl = nn.Linear(16, 3,32) (in this case it doesn’t work. l permuted dim 2 and dim 1 like this and it works cl = nn.Linear(16, 32,3)

If your import is of size (16,16,3)
then your Linear layer should be nn.Linear(3, output_features)
and will return output of size (16,16,output_features).

And if you feed it input of size (16,32,3)
then it will produce output of size (16,32,output_features)