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.7632  0.2810  0.4214  1.0396 -1.1381  0.1146 -0.2736  0.2023 -0.9280  0.7878
#> -0.1723  0.3042  2.0228 -1.5660  1.3553  2.2293  1.9791  0.5281  0.0593  0.7890
#>  0.2330 -0.2422 -0.1877 -0.3189 -0.1764 -2.6251  1.1144  0.1212 -0.1927 -0.0700
#> -0.2333 -2.2021 -0.5031 -0.4364  0.1855  0.9644 -0.0451 -1.4661  0.0332  1.5399
#> -0.4397  1.2286 -0.2231  1.6794 -0.4707  1.2328 -0.7574 -0.5367 -0.9753  0.3667
#> -0.0688 -0.0506  2.1000  0.9203  1.1087 -1.2492  0.4590  0.7516  0.4439  0.5029
#>  0.3703 -0.4536 -2.6524  0.3929  0.5185  1.6490  1.1421 -0.1846 -0.5367  1.5814
#> -0.5180  1.1667  0.7204 -1.6750 -0.6283 -0.2998 -0.6436 -0.3209 -0.6995 -0.5100
#>  1.6937  1.3783 -1.5059 -0.4531 -1.4647  0.7321 -0.5155 -2.4959  0.3491 -1.4431
#>  1.1198  0.1905  1.1057  1.2794  0.0631 -0.8351 -0.1907  0.7816  0.5159 -1.4470
#> -1.9306 -0.8498  0.3535 -3.0545 -0.6338 -1.2985  0.1247  0.5670 -1.1463 -0.8359
#>  0.9621  2.1583  0.7324  0.9715 -0.4880 -0.5359  0.8453 -0.6889 -1.5020  2.5315
#> -1.0634  0.8456  0.4203  0.9391 -0.6651 -0.0270 -0.1085  0.0316  0.1794 -1.7271
#>  0.6858 -1.1257 -0.6133 -0.8256 -0.0750  1.1100  0.7263 -0.4768 -0.6100 -0.1258
#> -1.1293  0.2364  0.7978  1.0512  1.5963  0.8823 -1.4669 -0.3796 -0.3067 -0.0017
#> -0.6229 -0.3339 -0.7223 -0.0216 -0.1665  0.6086 -0.2687  0.6164 -0.8208  0.2784
#> -0.2907 -0.5651 -0.4396 -1.5572  0.3477  0.3215  0.4914  1.2559  0.0052 -0.3231
#>  0.7349 -0.4432 -0.2857 -1.7722 -0.9685  1.4400 -0.3253  1.8455 -0.1247  0.4748
#> -0.6698  0.9732  1.0199  1.3378  1.4279  0.8932 -0.6528 -0.2240 -1.3905 -1.7372
#> -1.3844 -0.2063  0.6833 -0.6148  1.2685  0.5141  0.3164 -0.3219 -1.6151  0.1800
#> -1.1240  0.3548 -0.2726  0.8631 -0.6896 -1.8439 -0.1746 -0.9763 -0.4039 -0.5143
#> -0.5452 -0.5008 -2.6252  1.3891 -0.6107 -0.2065  0.4299  1.3791 -0.5231  1.2390
#> -0.1084 -0.0734 -0.4444  0.7359  2.4896 -0.0347 -0.3267  0.2620 -1.7932  0.2558
#> -0.1292  0.5362  1.5294  0.7775  1.6975  1.5585  1.5743 -0.0909  0.2590 -1.0780
#> -0.7613  0.1335 -0.0921 -0.0023  2.0488 -0.1532  0.1871  0.0136  0.8705  1.1874
#> -0.3778  0.4823  1.7534 -0.9323 -1.1045  1.1765  0.4833 -1.5904  1.9655  0.7473
#>  0.8026 -0.4689 -0.8736  1.5259 -0.5601  1.0169  0.6834  0.1357 -1.9728  0.2429
#> -0.4672  0.7041 -0.1127  1.7013  1.8236  0.1509  0.4093  0.9455 -1.2859 -0.0207
#> -0.3371  1.4460 -0.4156  1.4929  0.3115  0.2343  0.9265  0.3517 -1.7912 -1.7389
#>  0.4365  1.5458  0.9424 -0.2428 -0.2159  0.1873  1.2397  1.0246  1.4802 -1.6494
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{32,25} ]