📄 m1_multiply_doc.html
字号:
2.7470 5.0786 4.7737 2.7583 2.4439 4.5664 4.2765 2.4655 2.6095 4.8234 4.5165 2.6018 Y(:,:,2,2) = 1.4740 2.7639 2.5977 1.5023 2.8931 5.3300 4.9868 2.8703 2.5479 4.7381 4.4189 2.5385 2.7060 4.9891 4.6705 2.6895 Y(:,:,3,2) = 1.0365 1.9368 1.8275 1.0598 1.9305 3.6151 3.4161 1.9837 1.7213 3.2586 3.0731 1.7830 1.8406 3.4297 3.2279 1.8680 Y(:,:,1,3) = 1.3367 2.4889 2.3411 1.3540 2.5428 4.6564 4.3894 2.5403 2.2559 4.1595 3.9180 2.2671 2.4183 4.4405 4.1641 2.4005 Y(:,:,2,3) = 1.3373 2.4918 2.3410 1.3528 2.6485 4.8327 4.5351 2.6148 2.3258 4.2653 4.0063 2.3123 2.4723 4.5286 4.2431 2.4440 Y(:,:,3,3) = 0.9845 1.8150 1.7108 0.9905 1.8066 3.3375 3.1542 1.8302 1.6093 2.9879 2.8273 1.6426 1.7309 3.1876 2.9998 1.7345</pre><pre class="codeinput">Y = ttm(X, {C,D}, [3 4]); <span class="comment">%<-- X times C in mode-3 & D in mode-4</span>Y = ttm(X, {A,B,C,D}, [3 4]) <span class="comment">%<-- Same as above.</span></pre><pre class="codeoutput">Y is a tensor of size 5 x 3 x 3 x 3 Y(:,:,1,1) = 1.5822 1.3415 1.3949 1.2553 1.1977 1.2159 1.4244 1.6067 1.3862 1.2104 0.7492 1.5089 1.2932 1.3210 1.1591 Y(:,:,2,1) = 1.5112 1.0441 1.3712 1.1439 1.2984 1.2236 1.5205 1.6549 1.5110 1.3913 0.8995 1.5692 1.2733 1.4256 1.0567 Y(:,:,3,1) = 1.0920 1.0458 1.1802 0.9569 0.8498 0.8816 0.9992 1.0501 0.9638 0.8583 0.5944 1.0157 0.9676 1.0079 0.8150 Y(:,:,1,2) = 0.9474 0.8303 0.7452 0.8904 0.7530 0.6234 0.7403 0.9461 0.8350 0.8144 0.4605 0.7893 0.7803 0.6910 0.7280 Y(:,:,2,2) = 0.9542 0.7092 0.7569 0.8336 0.8635 0.6079 0.8297 0.9292 0.9154 0.8980 0.5883 0.7834 0.8064 0.7848 0.7567 Y(:,:,3,2) = 0.6673 0.6108 0.5736 0.6973 0.4752 0.4593 0.5460 0.6273 0.5737 0.5921 0.3631 0.5820 0.5514 0.4938 0.5138 Y(:,:,1,3) = 0.8673 0.7494 0.7182 0.7597 0.6751 0.6126 0.7228 0.8726 0.7625 0.7098 0.4168 0.7683 0.7120 0.6726 0.6529 Y(:,:,2,3) = 0.8539 0.6157 0.7186 0.7037 0.7561 0.6064 0.7919 0.8754 0.8338 0.7962 0.5187 0.7797 0.7207 0.7460 0.6432 Y(:,:,3,3) = 0.6056 0.5653 0.5783 0.5887 0.4485 0.4479 0.5208 0.5749 0.5266 0.5108 0.3295 0.5433 0.5160 0.4959 0.4601</pre><pre class="codeinput">Y = ttm(X, {A,B,D}, [1 2 4]); <span class="comment">%<-- 3-way multiply.</span>Y = ttm(X, {A,B,C,D}, [1 2 4]); <span class="comment">%<-- Same as above.</span>Y = ttm(X, {A,B,D}, -3); <span class="comment">%<-- Same as above.</span>Y = ttm(X, {A,B,C,D}, -3) <span class="comment">%<-- Same as above.</span></pre><pre class="codeoutput">Y is a tensor of size 4 x 4 x 4 x 3 Y(:,:,1,1) = 1.0560 2.1553 2.0387 1.1911 2.4278 4.3898 4.2181 2.4754 2.1441 3.9274 3.7356 2.1771 2.2457 4.2196 3.9658 2.2936 Y(:,:,2,1) = 1.3324 2.2654 2.0972 1.1901 2.6489 4.6589 4.2674 2.4065 2.2210 3.9024 3.6500 2.0934 2.3874 4.1487 3.8458 2.1882 Y(:,:,3,1) = 1.5259 2.6902 2.5346 1.4625 2.4233 4.3577 4.1285 2.3958 2.1583 3.9709 3.7404 2.1642 2.4544 4.4132 4.1332 2.3769 Y(:,:,4,1) = 1.2470 2.3630 2.2327 1.2974 2.4531 4.5551 4.3305 2.5251 2.2263 4.0016 3.8576 2.2685 2.3016 4.2637 4.0530 2.3627 Y(:,:,1,2) = 0.6944 1.3989 1.3155 0.7645 1.4979 2.6951 2.5093 1.4364 1.3402 2.4234 2.2267 1.2614 1.4163 2.6071 2.4098 1.3735 Y(:,:,2,2) = 0.8962 1.5379 1.4173 0.8018 1.6626 3.0068 2.7746 1.5774 1.4220 2.6151 2.4249 1.3856 1.5214 2.7047 2.5241 1.4463 Y(:,:,3,2) = 0.8062 1.4427 1.3306 0.7556 1.3527 2.4504 2.3102 1.3362 1.2317 2.2839 2.1471 1.2410 1.3547 2.4308 2.2533 1.2850 Y(:,:,4,2) = 0.6588 1.3312 1.3007 0.7781 1.3637 2.6926 2.5765 1.5156 1.2072 2.3770 2.2702 1.3333 1.2520 2.4805 2.3848 1.4080 Y(:,:,1,3) = 0.6109 1.2374 1.1665 0.6794 1.3537 2.4408 2.3039 1.3333 1.2045 2.1900 2.0426 1.1717 1.2680 2.3547 2.1921 1.2574 Y(:,:,2,3) = 0.7812 1.3355 1.2330 0.6984 1.4915 2.6660 2.4525 1.3896 1.2650 2.2829 2.1244 1.2158 1.3562 2.3881 2.2224 1.2697 Y(:,:,3,3) = 0.7811 1.3880 1.2929 0.7398 1.2777 2.3069 2.1797 1.2626 1.1519 2.1284 2.0027 1.1581 1.2862 2.3100 2.1515 1.2317 Y(:,:,4,3) = 0.6383 1.2522 1.2053 0.7119 1.2905 2.4790 2.3654 1.3861 1.1555 2.1838 2.0942 1.2306 1.1966 2.2999 2.2001 1.2917</pre><h2>Sparse tensor times matrix (ttm for sptensor)<a name="33"></a></h2> <p>It is also possible to multiply an sptensor times a matrix or series of matrices. The arguments are the same as for the dense case. The result may be dense or sparse, depending on its density. </p><pre class="codeinput">X = sptenrand([5 3 4 2],10);Y = ttm(X, A, 1); <span class="comment">%<-- X times A in mode-1.</span>Y = ttm(X, {A,B,C,D}, 1); <span class="comment">%<-- Same as above.</span>Y = ttm(X, A', 1, <span class="string">'t'</span>) <span class="comment">%<-- Same as above</span></pre><pre class="codeoutput">Y is a sparse tensor of size 4 x 3 x 4 x 2 with 28 nonzeros (1,1,1,1) 0.1506 (1,2,2,1) 0.0129 (1,3,2,1) 0.0893 (1,2,1,2) 0.4196 (1,1,2,2) 0.0066 (1,3,2,2) 0.0377 (1,3,3,2) 0.4310 (2,1,1,1) 0.7738 (2,2,2,1) 0.3652 (2,3,2,1) 0.4116 (2,2,1,2) 0.2315 (2,1,2,2) 0.1852 (2,3,2,2) 0.2910 (2,3,3,2) 0.7843 (3,1,1,1) 0.8920 (3,2,2,1) 0.2743 (3,3,2,1) 0.3639 (3,2,1,2) 0.3365 (3,1,2,2) 0.1391 (3,3,2,2) 0.2387 (3,3,3,2) 0.9501 (4,1,1,1) 0.5556 (4,2,2,1) 0.3154 (4,3,2,1) 0.1610 (4,2,1,2) 0.4202 (4,1,2,2) 0.1600 (4,3,2,2) 0.1799 (4,3,3,2) 0.7447</pre><pre class="codeinput">norm(full(Y) - ttm(full(X),A, 1) ) <span class="comment">%<-- Same as dense case.</span></pre><pre class="codeoutput">ans = 0</pre><pre class="codeinput">Y = ttm(X, {A,B,C,D}, [1 2 3 4]); <span class="comment">%<-- 4-way multiply.</span>Y = ttm(X, {D,C,B,A}, [4 3 2 1]); <span class="comment">%<-- Same as above.</span>Y = ttm(X, {A,B,C,D}); <span class="comment">%<-- Same as above.</span>Y = ttm(X, {A',B',C',D'}, <span class="string">'t'</span>) <span class="comment">%<-- Same as above.</span></pre><pre class="codeoutput">Y is a tensor of size 4 x 4 x 3 x 3 Y(:,:,1,1) = 0.0890 0.1395 0.1470 0.0913 0.2458 0.5003 0.5113 0.3157 0.2497 0.5323 0.5461 0.3388 0.2063 0.4095 0.3985 0.2375 Y(:,:,2,1) = 0.0985 0.1757 0.1675 0.0976 0.3510 0.7241 0.7029 0.4190 0.3310 0.7403 0.7158 0.4273 0.2770 0.5858 0.5249 0.2942 Y(:,:,3,1) = 0.0419 0.0376 0.0617 0.0462 0.1291 0.1583 0.1999 0.1358 0.1288 0.1546 0.2055 0.1430 0.1050 0.1303 0.1583 0.1054 Y(:,:,1,2) = 0.0981 0.1224 0.1323 0.0821 0.1729 0.2599 0.3046 0.2013 0.1919 0.2865 0.3360 0.2219 0.1682 0.2465 0.2699 0.1710 Y(:,:,2,2) = 0.0973 0.1452 0.1299 0.0708 0.1977 0.3532 0.3625 0.2229 0.2021 0.3706 0.3744 0.2280 0.1835 0.3276 0.3052 0.1747 Y(:,:,3,2) = 0.0483 0.0371 0.0666 0.0510 0.1054 0.0994 0.1585 0.1176 0.1157 0.1031 0.1730 0.1305 0.0945 0.0895 0.1386 0.1018 Y(:,:,1,3) = 0.0719 0.0965 0.1034 0.0642 0.1480 0.2538 0.2795 0.1794 0.1587 0.2752 0.3040 0.1956 0.1361 0.2251 0.2346 0.1450 Y(:,:,2,3) = 0.0738 0.1169 0.1071 0.0599 0.1860 0.3555 0.3552 0.2152 0.1835 0.3684 0.3644 0.2199 0.1610 0.3092 0.2830 0.1605 Y(:,:,3,3) = 0.0350 0.0282 0.0491 0.0374 0.0853 0.0892 0.1296 0.0932 0.0905 0.0902 0.1384 0.1016 0.0739 0.0773 0.1094 0.0777</pre><pre class="codeinput">Y = ttm(X, {C,D}, [3 4]); <span class="comment">%<-- X times C in mode-3 & D in mode-4</span>Y = ttm(X, {A,B,C,D}, [3 4]) <span class="comment">%<-- Same as above.</span></pre><pre class="codeoutput">Y is a tensor of size 5 x 3 x 3 x 3 Y(:,:,1,1) = 0 0.1004 0.0998 0.4075 0 0.1363 0.0221 0.1332 0.0167 0 0 0.3307 0 0 0 Y(:,:,2,1) = 0 0.1323 0.0395 0.5371 0 0.0540 0.0427 0.2578 0.0322 0 0 0.6257 0 0 0 Y(:,:,3,1) = 0 0.0154 0.0943 0.0626 0 0.1289 0.0123 0.0742 0.0093 0 0 0.1878 0 0 0 Y(:,:,1,2) = 0 0.1342 0.1334 0.1478 0 0.1823 0.0295 0.0483 0.0223 0 0 0.1626 0 0 0 Y(:,:,2,2) = 0 0.1769 0.0528 0.1948 0 0.0722 0.0571 0.0935 0.0431 0 0 0.2955 0 0 0 Y(:,:,3,2) = 0 0.0206 0.1262 0.0227 0 0.1724 0.0164 0.0269 0.0124 0 0 0.0954 0 0 0 Y(:,:,1,3) = 0 0.0933 0.0927 0.1737 0 0.1267 0.0205 0.0568 0.0155 0 0 0.1630 0 0 0 Y(:,:,2,3) = 0 0.1229 0.0367 0.2290 0 0.0502 0.0397 0.1099 0.0300 0 0 0.3022 0 0 0 Y(:,:,3,3) = 0 0.0143 0.0877 0.0267 0 0.1198 0.0114 0.0316 0.0086 0 0 0.0942 0 0 0</pre><pre class="codeinput">Y = ttm(X, {A,B,D}, [1 2 4]); <span class="comment">%<-- 3-way multiply.</span>Y = ttm(X, {A,B,C,D}, [1 2 4]); <span class="comment">%<-- Same as above.</span>Y = ttm(X, {A,B,D}, -3); <span class="comment">%<-- Same as above.</span>Y = ttm(X, {A,B,C,D}, -3) <span class="comment">%<-- Same as above.</span></pre><pre class="codeoutput">Y is a tensor of size 4 x 4 x 4 x 3 Y(:,:,1,1) = 0.1010 0.2463 0.1918 0.0950 0.1515 0.7021 0.6066 0.3415 0.1879 0.8297 0.7130 0.3989 0.1573 0.5785 0.4856 0.2645 Y(:,:,2,1) = 0.0416 0.0313 0.0563 0.0431 0.3903 0.4667 0.4983 0.3058 0.3136 0.3615 0.4026 0.2533 0.2647 0.3646 0.3297 0.1801 Y(:,:,3,1) = 0.0468 0.0249 0.0651 0.0543 0.0851 0.0453 0.1184 0.0988 0.1031 0.0549 0.1434 0.1196 0.0808 0.0430 0.1124 0.0938 Y(:,:,4,1) = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Y(:,:,1,2) = 0.1147 0.2091 0.1501 0.0656 0.0980 0.3207 0.2645 0.1410 0.1308 0.3970 0.3232 0.1696 0.1353 0.3298 0.2568 0.1271 Y(:,:,2,2) = 0.0194 0.0152 0.0275 0.0211 0.1805 0.2340 0.2663 0.1713 0.1451 0.1809 0.2133 0.1397 0.1221 0.1841 0.1830 0.1087 Y(:,:,3,2) = 0.0626 0.0333 0.0870 0.0726 0.1138 0.0606 0.1584 0.1321 0.1379 0.0735 0.1919 0.1600 0.1081 0.0576 0.1504 0.1254 Y(:,:,4,2) = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Y(:,:,1,3) = 0.0834 0.1668 0.1233 0.0566 0.0868 0.3335 0.2816 0.1545 0.1125 0.4033 0.3373 0.1830 0.1074 0.3086 0.2487 0.1289 Y(:,:,2,3) = 0.0200 0.0153 0.0277 0.0212 0.1865 0.2324 0.2566 0.1616 0.1499 0.1798 0.2064 0.1327 0.1263 0.1822 0.1733 0.0992 Y(:,:,3,3) = 0.0435 0.0232 0.0605 0.0504 0.0791 0.0421 0.1100 0.0918 0.0958 0.0510 0.1333 0.1112 0.0751 0.0400 0.1045 0.0872 Y(:,:,4,3) = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</pre><p>The result may be dense or sparse.</p><pre class="codeinput">X = sptenrand([5 3 4],1);Y = ttm(X, A, 1) <span class="comment">%<-- Sparse result.</span></pre><pre class="codeoutput">Y is a sparse tensor of size 4 x 3 x 4 with 4 nonzeros (1,3,2) 0.0232 (2,3,2) 0.1067 (3,3,2) 0.0943 (4,3,2) 0.0417</pre><pre class="codeinput">X = sptenrand([5 3 4],50);Y = ttm(X, A, 1) <span class="comment">%<-- Dense result.</span></pre><pre class="codeoutput">Y is a tensor of size 4 x 3 x 4 Y(:,:,1) = 0.4159 0.5631 0.0406 0.9765 1.4239 0.2088 0.9029 1.2234 0.2406 0.8744 1.2606 0.1499 Y(:,:,2) = 1.0127 0.5477 0 1.4153 1.1141 0 1.1989 1.0105 0 1.6381 0.9835 0 Y(:,:,3) = 0.5923 0.6934 0.9184 0.8260 0.9650 0.8641 0.4955 0.7236 0.5323 0.8762 0.9604 1.0351 Y(:,:,4) = 1.2906 0.7036 0.4899 1.2638 0.8427 1.1469 1.1332 0.8936 1.0464 1.5305 0.9649 0.9588
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -