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.2295  0.4362  1.6050  0.0335  0.4784 -1.1112 -0.6461  0.3078 -1.3921 -0.7668
#> -0.7642  1.9982 -0.4341 -0.4532  0.2037 -0.2663 -0.1438  1.3869  0.0617  2.0667
#> -0.2872  1.4088  0.0565  1.4522  0.4711 -1.2428  1.4250  0.0634  0.6652 -0.6660
#>  1.0235  0.8120 -0.4498 -1.4263 -0.8501 -2.2504 -0.7781  0.2414  0.4233  0.2361
#>  0.9937 -0.0636 -0.3535 -0.1386  0.6432 -0.5219 -1.9646 -0.1116  0.8496  0.7957
#> -0.1244  0.7749 -0.1648  1.2808 -0.2340  0.1028  1.7092 -0.7911  0.1381  1.6842
#>  1.8027  0.1494 -0.2372 -0.2083 -0.4606 -0.4370 -0.3579 -0.6743 -0.0737 -1.1094
#> -0.4190 -0.1215 -0.3891  0.6279  1.1536 -0.2149  0.0721  0.9220  1.1007 -0.3022
#> -0.8114  0.7703 -0.5618 -0.7049 -0.6881  1.7096 -0.4178 -0.1619 -0.0357  0.7077
#>  0.7295 -0.9758 -0.2203  1.3707 -0.4356 -1.0506 -1.3614  1.0917 -0.5067 -0.0593
#> -0.8482 -2.5384  1.0779  0.6191  1.4364 -2.4517  0.5286 -0.8921 -0.7623 -0.6412
#>  1.0567  0.5949  0.6233  0.3384 -1.3294  0.1811 -0.1477 -0.0044 -0.2256 -0.8347
#>  0.1329  0.7662 -0.2160  0.0901 -0.3512 -0.8072 -1.4545  0.3374  0.5284 -1.4438
#>  0.3579  0.5064 -0.3833  1.0813 -1.2426  0.3001 -0.7318 -1.2021  0.3301 -0.7103
#>  0.7681  1.7418  0.3482 -0.0485 -1.5191 -0.6493  0.3266 -0.7553  0.3702  0.3649
#>  0.8630  1.1557 -0.5514  0.9015 -1.1675 -2.6105  0.3215 -1.7240  1.5964 -0.1115
#>  0.5449 -0.9217  0.2538  1.3738 -0.3347  0.1456 -1.0685  0.6739  0.8506 -0.4578
#>  0.0280 -0.0833  0.3444  1.7292  1.0207 -0.5314 -0.1009 -0.8973  0.0016 -0.7684
#> -0.9136 -0.1908 -0.0054  0.8179  1.2029  0.2395  1.4798 -1.5940  1.4535 -2.0211
#> -1.4229 -0.6965  0.2951  0.7101 -0.2496  1.1673 -0.6657  0.2565  1.3454 -0.9639
#>  0.3115 -0.7621  0.0672  0.6930 -0.2573  1.3647 -0.4824 -0.5175 -1.8281  0.9719
#> -0.7096 -1.0501  0.6509 -0.5622 -1.6341 -0.6459  1.2285  1.0851 -2.1462 -0.5760
#> -0.3399 -0.6048  0.0276  0.7101  0.5877 -0.2741  0.0280 -2.4010  0.6318 -0.9695
#>  0.0875 -0.1775  0.2311 -1.3256 -0.8035  1.0643 -1.5354  1.1389  1.5720 -1.6892
#>  0.5346 -0.0384 -2.6469  0.1998 -1.2819  0.1685 -1.5668  1.5784 -0.0910 -0.1001
#> -0.6491  0.7580  0.2500 -0.3513  1.0647 -0.9089  0.3192  2.5194 -1.6044  1.1133
#> -0.5474  0.2001  1.2237 -0.1022  0.0681  1.1650 -0.3524  0.6637 -0.9775 -0.8528
#>  0.4275  1.4706 -0.3852 -1.1646  2.0296 -0.0732 -1.8171  0.5053  0.0826 -0.5935
#> -1.5131  0.4807  0.6342  1.2742 -0.1451 -0.8920  1.9078 -1.3114 -0.9096 -1.3673
#> -1.0696 -1.0839 -0.3178 -0.2872 -1.0751  1.3007 -0.2716  1.1977  0.6324  2.3960
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{32,25} ]