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-1.1286 -1.5693  1.1629 -2.1835 -0.8965 -0.6284  0.5097 -0.9533 -0.2732 -0.8154
#>  0.3395 -1.4428  0.4602  1.1894 -0.5107  0.5262  0.9335  0.8602 -0.1029 -0.9297
#> -0.9586 -1.5237 -0.1057 -0.4734  2.1590 -0.5596  0.4289  0.6230  0.7002  0.8150
#> -0.4952  0.5850 -0.1334 -0.6514  1.3206 -1.1515 -2.2976  0.2404  0.2667 -1.7543
#>  1.1279 -1.3131 -0.9311 -0.8063 -0.3390 -0.1139 -1.6560 -0.4785 -1.1279  0.3019
#>  0.6553  0.3122  0.0104  1.0357 -0.6349 -1.5390 -0.2028  0.6194 -1.8117 -0.3647
#>  1.4251 -1.0049  0.3986  0.6041 -0.4381  1.0610  0.0582 -0.8204  1.3138  0.8401
#> -0.6779  0.7251 -0.7368 -0.5256  0.6982 -0.9914  0.0900  0.5162 -1.8286 -0.9027
#>  1.8609 -0.4633  0.2078 -0.4287 -0.3061  0.2204 -0.0694 -0.2644  0.0906 -0.4326
#> -0.0733 -1.1715  1.0491 -1.3368  0.8180  0.1737  0.7204  2.1689  0.3281  0.5951
#> -0.8653 -1.4753  0.5333 -0.4475 -1.0022 -0.4576  0.7900  1.1400 -1.4934  0.6701
#> -0.1516  0.1201 -0.1525 -0.6256 -0.7953 -0.5968 -0.6606  1.2147  0.5342 -0.7769
#> -0.2480 -0.1987 -1.8152  0.9277 -0.3543 -1.2049  0.3064  0.9992  1.0888  0.6377
#>  0.1544 -0.7643 -1.1094  1.1278 -0.4194  0.0373 -0.1862  0.6767  0.6714  0.5042
#> -0.9894  0.0389 -0.3946  0.7267 -0.2514  0.5392 -0.4532  0.1955  0.3764  0.0150
#>  0.3734  1.1094  0.5318  0.7432 -0.0535 -0.7077  0.8758  0.2191 -0.1117  0.7116
#>  1.4979  0.1757  0.4725 -0.1434  0.2728 -2.3261  0.0516 -0.5707 -0.9935 -0.3126
#> -0.9373 -0.3477 -0.2269  0.9724 -0.4871  0.0695  0.3406 -0.1757  1.0202 -1.0403
#>  0.1928 -0.5047 -0.7363 -0.4739 -1.9774 -0.5826  0.6849 -0.5083  0.2665  0.7113
#> -0.0825 -0.3199  1.3136  0.0390 -1.2495 -1.9408 -0.2430  0.1429 -0.3340 -0.9111
#>  1.5771  1.6697 -0.5537 -0.2823  0.9513 -0.2057 -0.7667  1.0565  0.5093  1.4640
#>  1.6454 -0.7786 -0.1625  0.4589 -0.3007 -1.1129 -1.0692 -0.0311  0.7675  0.3377
#>  1.4310 -0.9069 -1.3820 -0.0540 -0.1846 -0.9834  0.5401  1.3809 -1.0555 -0.2179
#> -1.7490 -0.7685 -0.2488  1.5312 -0.0577 -1.3659 -1.9510  0.3062 -0.5033 -0.2865
#>  0.4856 -1.7295 -0.3246  0.5200 -0.3371  0.1446  0.3847 -0.6658 -0.3260 -0.5136
#> -0.3698 -0.7538  1.6902 -1.0013 -0.0677  0.6341 -0.4957  1.8021  0.1075 -0.4392
#>  1.5946  0.0303 -1.9103 -0.4039 -2.5023 -1.5781 -0.7800 -0.5373  2.6896 -0.1973
#> -0.7442 -2.3169 -0.1286 -1.8256 -1.5317 -0.8394  0.6230  0.7055 -0.1841  0.1340
#> -1.3325 -0.5921  1.2759 -0.6718 -0.9200 -1.0678  2.0083  1.2248  0.2666  0.6203
#>  2.7377  1.9385 -0.5903  0.7199 -0.3692 -0.2438  0.7998 -1.7725 -1.5050  0.2406
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{32,25} ]