{"id":384,"date":"2023-03-16T01:16:52","date_gmt":"2023-03-16T01:16:52","guid":{"rendered":"https:\/\/yunshangtulv.com.cn\/?p=384"},"modified":"2023-03-16T01:19:17","modified_gmt":"2023-03-16T01:19:17","slug":"%e7%9f%a9%e9%98%b5%e8%af%a6%e8%a7%a3%e5%8f%8a%e5%ba%94%e7%94%a8%e4%b8%be%e4%be%8b","status":"publish","type":"post","link":"https:\/\/yunshangtulv.com.cn\/?p=384","title":{"rendered":"\u77e9\u9635\u8be6\u89e3\u53ca\u5e94\u7528\u4e3e\u4f8b"},"content":{"rendered":"<p>R\u8bed\u8a00\u4e2d\u7684\u77e9\u9635(matrix)\u662f\u4e00\u4e2a\u4e8c\u7ef4\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u5fc5\u987b\u662f\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u901a\u8fc7\u884c\u53f7\u548c\u5217\u53f7\u6765\u8bbf\u95ee\uff0c\u7c7b\u4f3c\u4e8e\u4e8c\u7ef4\u6570\u7ec4\u3002\u5728R\u8bed\u8a00\u4e2d\uff0c\u77e9\u9635\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570matrix()\u521b\u5efa\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-r\"><span class=\"hljs-comment\"># \u521b\u5efa\u4e00\u4e2a3\u884c4\u5217\u7684\u77e9\u9635<\/span><br \/>\nmat <span class=\"hljs-operator\">&lt;-<\/span> matrix<span class=\"hljs-punctuation\">(<\/span><span class=\"hljs-number\">1<\/span><span class=\"hljs-operator\">:<\/span><span class=\"hljs-number\">12<\/span><span class=\"hljs-punctuation\">,<\/span> nrow <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">3<\/span><span class=\"hljs-punctuation\">,<\/span> ncol <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">4<\/span><span class=\"hljs-punctuation\">)<\/span><br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>mat<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u8fd9\u4e2a\u793a\u4f8b\u4ee3\u7801\u5c06\u4f1a\u521b\u5efa\u4e00\u4e2a3\u884c4\u5217\u7684\u77e9\u9635\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u4e3a1\u523012\u7684\u6574\u6570\u3002\u51fd\u6570matrix()\u63a5\u53d7\u4e00\u4e2a\u6570\u636e\u5411\u91cf\u548c\u4e24\u4e2a\u53c2\u6570nrow\u548cncol\u6765\u6307\u5b9a\u77e9\u9635\u7684\u884c\u6570\u548c\u5217\u6570\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u4e00\u4e9bR\u8bed\u8a00\u4e2d\u77e9\u9635\u7684\u5e38\u7528\u64cd\u4f5c\u53ca\u5e94\u7528\u4e3e\u4f8b\uff1a<\/p>\n<ol>\n<li>\n<h3>\u8bbf\u95ee\u77e9\u9635\u5143\u7d20<\/h3>\n<\/li>\n<\/ol>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u884c\u53f7\u548c\u5217\u53f7\u6765\u8bbf\u95ee\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7mat[1, 2]\u6765\u8bbf\u95ee\u7b2c1\u884c\u7b2c2\u5217\u7684\u5143\u7d20\u3002<\/p>\n<ol start=\"2\">\n<li>\n<h3>\u77e9\u9635\u7684\u8f6c\u7f6e<\/h3>\n<\/li>\n<\/ol>\n<p>\u4f7f\u7528\u51fd\u6570t()\u53ef\u4ee5\u5c06\u77e9\u9635\u8f6c\u7f6e\uff0c\u884c\u53d8\u6210\u5217\uff0c\u5217\u53d8\u6210\u884c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u60f3\u5c06\u4e0a\u9762\u7684\u793a\u4f8b\u77e9\u9635mat\u8f6c\u7f6e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-r\">t<span class=\"hljs-punctuation\">(<\/span>mat<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<ol start=\"3\">\n<li>\n<h3>\u77e9\u9635\u7684\u52a0\u6cd5\u548c\u51cf\u6cd5<\/h3>\n<\/li>\n<\/ol>\n<p>\u5bf9\u4e8e\u4e24\u4e2a\u540c\u6837\u5927\u5c0f\u7684\u77e9\u9635\uff0c\u53ef\u4ee5\u5bf9\u5b83\u4eec\u8fdb\u884c\u52a0\u6cd5\u548c\u51cf\u6cd5\u8fd0\u7b97\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u6709\u4e24\u4e2a3\u884c4\u5217\u7684\u77e9\u9635mat1\u548cmat2\uff0c\u5e76\u60f3\u5bf9\u5b83\u4eec\u8fdb\u884c\u52a0\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-r\">mat1 <span class=\"hljs-operator\">&lt;-<\/span> matrix<span class=\"hljs-punctuation\">(<\/span><span class=\"hljs-number\">1<\/span><span class=\"hljs-operator\">:<\/span><span class=\"hljs-number\">12<\/span><span class=\"hljs-punctuation\">,<\/span> nrow <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">3<\/span><span class=\"hljs-punctuation\">,<\/span> ncol <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">4<\/span><span class=\"hljs-punctuation\">)<\/span><br \/>\nmat2 <span class=\"hljs-operator\">&lt;-<\/span> matrix<span class=\"hljs-punctuation\">(<\/span><span class=\"hljs-number\">13<\/span><span class=\"hljs-operator\">:<\/span><span class=\"hljs-number\">24<\/span><span class=\"hljs-punctuation\">,<\/span> nrow <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">3<\/span><span class=\"hljs-punctuation\">,<\/span> ncol <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">4<\/span><span class=\"hljs-punctuation\">)<\/span><\/p>\n<p><span class=\"hljs-comment\"># \u77e9\u9635\u52a0\u6cd5<\/span><br \/>\nmat_add <span class=\"hljs-operator\">&lt;-<\/span> mat1 <span class=\"hljs-operator\">+<\/span> mat2<br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>mat_add<span class=\"hljs-punctuation\">)<\/span><\/p>\n<p><span class=\"hljs-comment\"># \u77e9\u9635\u51cf\u6cd5<\/span><br \/>\nmat_sub <span class=\"hljs-operator\">&lt;-<\/span> mat1 <span class=\"hljs-operator\">-<\/span> mat2<br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>mat_sub<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<ol start=\"4\">\n<li>\n<h3>\u77e9\u9635\u7684\u4e58\u6cd5<\/h3>\n<\/li>\n<\/ol>\n<p>\u77e9\u9635\u4e58\u6cd5\u5728R\u8bed\u8a00\u4e2d\u4f7f\u7528%*%\u8fd0\u7b97\u7b26\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u6709\u4e00\u4e2a3\u884c2\u5217\u7684\u77e9\u9635A\u548c\u4e00\u4e2a2\u884c4\u5217\u7684\u77e9\u9635B\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u4eec\u76f8\u4e58\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-r\">A <span class=\"hljs-operator\">&lt;-<\/span> matrix<span class=\"hljs-punctuation\">(<\/span><span class=\"hljs-built_in\">c<\/span><span class=\"hljs-punctuation\">(<\/span><span class=\"hljs-number\">1<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">2<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">3<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">4<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">5<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">6<\/span><span class=\"hljs-punctuation\">)<\/span><span class=\"hljs-punctuation\">,<\/span> nrow <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">3<\/span><span class=\"hljs-punctuation\">,<\/span> ncol <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">2<\/span><span class=\"hljs-punctuation\">)<\/span><br \/>\nB <span class=\"hljs-operator\">&lt;-<\/span> matrix<span class=\"hljs-punctuation\">(<\/span><span class=\"hljs-built_in\">c<\/span><span class=\"hljs-punctuation\">(<\/span><span class=\"hljs-number\">7<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">8<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">9<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">10<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">11<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">12<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">13<\/span><span class=\"hljs-punctuation\">,<\/span><span class=\"hljs-number\">14<\/span><span class=\"hljs-punctuation\">)<\/span><span class=\"hljs-punctuation\">,<\/span> nrow <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">2<\/span><span class=\"hljs-punctuation\">,<\/span> ncol <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">4<\/span><span class=\"hljs-punctuation\">)<\/span><\/p>\n<p><span class=\"hljs-comment\"># \u77e9\u9635\u4e58\u6cd5<\/span><br \/>\nAB <span class=\"hljs-operator\">&lt;-<\/span> A <span class=\"hljs-operator\">%*%<\/span> B<br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>AB<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u521b\u5efa\u4e00\u4e2a3\u884c4\u5217\u7684\u77e9\u9635AB\uff0c\u662f\u77e9\u9635A\u548c\u77e9\u9635B\u76f8\u4e58\u7684\u7ed3\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>R\u8bed\u8a00\u4e2d\u7684\u77e9\u9635(matrix)\u662f\u4e00\u4e2a\u4e8c\u7ef4\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u5fc5\u987b\u662f\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u901a\u8fc7\u884c\u53f7\u548c [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-384","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=384"}],"version-history":[{"count":0,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/384\/revisions"}],"wp:attachment":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}