Skip to contents

For use with nn_sequential.

Usage

nn_flatten(start_dim = 2, end_dim = -1)

Arguments

start_dim

first dim to flatten (default = 2).

end_dim

last dim to flatten (default = -1).

Shape

  • Input: (*, S_start,..., S_i, ..., S_end, *), where S_i is the size at dimension i and * means any number of dimensions including none.

  • Output: (*, S_start*...*S_i*...S_end, *).

See also

Examples

if (torch_is_installed()) {
input <- torch_randn(32, 1, 5, 5)
m <- nn_flatten()
m(input)
}
#> torch_tensor
#> Columns 1 to 10-0.4564 -1.5073  0.5497  1.2690  0.2805  0.8745 -0.1714 -1.2182  0.5817  2.5260
#>  0.1726  1.8020  0.3345 -0.3391 -1.2676 -0.4416 -1.7936 -1.7196  1.6160 -0.7320
#> -0.0802  0.2737  0.6623 -0.9949  0.3428  0.0287  0.1118 -0.4883 -1.8418  0.1383
#>  0.9751  1.0405  0.8780  1.2091  0.5893  0.2838  1.5434  0.0994  0.3885 -0.7656
#>  0.2698  0.4232 -0.3511  0.1175  0.1361  0.0383  0.7326  1.4436 -1.4710  2.7677
#> -0.9150 -0.5797 -0.0834  0.8490  0.7260 -0.7782  0.7401 -1.0088  0.3847  0.4047
#>  0.5272  1.4707 -0.2838 -0.5025 -0.8974 -1.5952  2.6368  0.4668  1.0256 -0.7069
#>  0.4759 -2.1402 -0.1902  0.5277  1.2522 -0.5384 -0.6096  0.2944  0.9573  0.1592
#> -0.0209  1.2632 -1.9044  0.6052  0.3372 -0.4870 -0.2241 -1.0503  2.0364 -0.1824
#>  0.1214  0.7721  1.0641  0.3216  0.9411 -0.8525 -1.0814 -1.6334  0.5118  0.3395
#>  0.1396  0.2217 -0.1864 -2.4815  0.2841  1.4050  0.5889  0.6023 -0.1523 -0.2286
#>  0.2678  1.2935  1.1647 -0.9079 -1.2944  0.4700  1.3818 -0.2454 -0.6113 -0.2494
#>  1.0374  0.6224 -1.0964 -1.3096  0.8058  1.1509 -0.9216 -0.2936 -0.8257 -0.2227
#> -0.4486  1.2104  0.7425 -1.0250 -0.2056 -1.0988 -1.5947 -0.0354  0.3439  0.8311
#>  0.5120 -0.9835 -0.1008 -2.2105 -1.3647 -1.0679 -1.6044  0.4893 -0.6770  0.1899
#> -0.7842  0.2087  0.9352 -0.3174  1.0417 -0.4669  1.3730 -1.7400 -1.1924 -2.0405
#> -1.4671 -0.0890 -0.0270 -0.5465 -0.3102  0.9836  0.0224 -1.9111 -1.1364 -0.3986
#> -0.1907 -0.5955 -0.5841 -0.4615  1.1937  0.3206  0.3811 -0.1038  0.4761 -0.6049
#>  0.7128 -1.5405  0.2317 -0.5764  0.7383 -0.1455  1.5122 -0.6212  0.1258  0.5868
#> -0.7376  0.2268  1.3751  0.7903 -0.0813 -1.7839 -0.8434  0.5972  0.3105  1.7661
#> -1.4599 -0.3859 -1.0658  1.0453  1.6535 -1.4690  1.0379 -0.1948  0.8792  1.3892
#> -0.7044 -0.8459 -0.2484 -1.4675 -0.0218  0.1154  0.2738 -1.5023 -0.8953  1.1687
#> -0.7322 -0.8064 -0.1959 -0.1409  0.3140  0.3069  0.0245  0.7191 -0.1918 -0.4427
#>  0.4433  1.0745 -1.1966  1.0263  0.8565 -2.2794 -0.4021 -0.4019 -0.3807 -0.6614
#> -0.1984  0.2898  1.3428  0.3479 -0.2362 -0.2064 -1.2705  0.8913 -0.2967 -1.8749
#>  1.3018  2.1807  0.0172 -0.8683  0.0526 -0.3754 -1.5504  4.0639  1.5641 -0.7921
#>  0.5940 -0.5404 -0.2321  1.6841 -2.1358  1.5249  1.7429  1.7604 -0.7297 -0.4787
#>  0.4936  1.1300  1.7504 -0.4836 -1.7765 -0.6934  0.4544  0.1452  1.3361  0.3230
#>  0.7975  0.7564 -0.0099  0.1687  0.1865 -0.5273 -1.1146  0.8344 -0.0278 -0.5672
#>  1.9465  0.6860 -0.6113  0.5324  1.2483  1.5408 -1.9892  0.7030 -1.7189  0.7876
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{32,25} ]