For use with nn_sequential.
Shape
Input:
(*, S_start,..., S_i, ..., S_end, *)
, whereS_i
is the size at dimensioni
and*
means any number of dimensions including none.Output:
(*, S_start*...*S_i*...S_end, *)
.
Examples
if (torch_is_installed()) {
input <- torch_randn(32, 1, 5, 5)
m <- nn_flatten()
m(input)
}
#> torch_tensor
#> Columns 1 to 10 0.7815 -0.9216 0.1699 0.1152 2.1548 -0.5407 -0.3781 0.7615 0.3182 -0.8574
#> -0.9832 0.6793 0.8675 0.4983 -1.2282 -0.3332 -0.4461 -0.9655 0.4759 -0.1023
#> 0.0062 0.7361 1.8338 1.1024 0.3314 -1.2581 -1.8184 -1.7320 1.0691 -2.3011
#> -1.8084 1.6769 -0.1621 -0.2397 1.0932 -1.1170 0.0641 2.1635 0.8254 -0.7496
#> -0.6719 -0.7508 1.0796 1.5209 -0.5946 -0.1089 0.3717 -1.5812 -1.1147 -0.7584
#> -1.1140 0.0435 -1.1688 0.7608 0.6744 1.3830 0.8573 -0.3455 0.1661 -0.0531
#> 1.0143 1.5191 -0.1228 -0.1656 0.8978 -1.7626 0.8285 1.1289 -0.3004 -2.5304
#> -0.1843 0.1523 0.3696 0.2722 1.0013 -1.1634 -0.8178 -1.5524 0.7161 -1.1393
#> 0.4387 -1.8466 0.1480 -0.1267 0.4098 0.2664 -1.9241 1.1243 -1.7671 0.1651
#> 0.7291 2.8501 -0.8329 0.4269 -0.0730 -0.1439 -3.2483 0.3002 -0.3955 -0.8389
#> -0.7059 1.2505 0.8071 -0.2948 0.7957 -0.2239 0.3800 -0.9673 -1.3529 -0.9846
#> 0.5126 -1.8847 -1.0562 -0.6032 -0.1634 0.8142 1.5208 0.6206 1.0496 0.1410
#> 1.5942 1.7963 -1.2319 0.6606 -0.5661 0.7338 0.4615 -0.2527 3.0247 -1.8704
#> -0.6375 -1.9146 -1.3290 -0.6898 -0.3093 -0.1283 -0.5299 -0.5063 0.7312 -0.3211
#> 1.1043 0.0018 -0.8729 0.7998 -0.3671 0.4180 -1.4457 0.1789 1.5404 -1.0855
#> -0.1175 -1.1628 -1.3193 -1.4217 0.4870 0.1131 -0.9156 0.6825 -1.2871 1.7007
#> -0.1429 -1.4132 -2.2495 -0.2851 1.9462 -0.4697 -1.9250 -0.1375 -0.1547 -0.4731
#> -1.0298 -1.5706 0.6897 0.5915 0.6087 0.1700 -0.1790 -0.8947 -1.4112 0.5943
#> -0.7398 -1.1171 -0.9756 -0.0213 -2.4743 1.3341 -0.9720 1.3449 -1.1762 -0.8379
#> -0.1971 0.4570 0.5956 -1.5039 0.4385 0.5537 -0.1144 0.2210 0.3769 1.6898
#> 0.2711 0.3167 -0.5235 -0.0366 -1.4653 -0.4550 -0.2064 -0.6326 0.9467 -0.6903
#> 0.1789 -0.6414 0.9133 -0.4242 -1.2109 -0.4718 1.0265 -1.3170 1.0668 1.5787
#> -0.9770 -0.0390 1.0604 0.6794 -0.2683 -0.5172 0.8470 0.2523 0.4452 -0.5226
#> -1.0192 0.3601 -1.4602 -0.0017 -0.1359 0.9426 1.9003 -0.2165 0.1125 -1.2849
#> 0.0197 -1.0769 -0.4867 0.6205 -0.8576 -0.5264 -1.5079 1.0182 -1.3411 0.2347
#> 0.2687 0.5811 1.3578 1.1773 0.1349 0.2014 -0.5129 -0.3566 -0.9541 0.0267
#> -0.3314 -1.0426 -1.3992 0.5741 0.6680 -0.0576 -0.9622 1.1348 1.5647 1.1856
#> 0.8979 -0.7524 -0.0222 -0.0366 -0.1139 -1.7778 0.3693 1.2656 -0.2839 -0.8981
#> 0.5922 0.1434 -2.0587 -0.8918 0.7347 1.4906 -1.1578 1.5241 -0.9877 0.2097
#> 0.6374 -0.1268 1.6524 -0.6022 -1.0846 0.2305 -1.1407 -1.0602 0.1957 0.2920
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{32,25} ]