{"id":22,"date":"2024-09-10T07:23:47","date_gmt":"2024-09-09T23:23:47","guid":{"rendered":"http:\/\/chaixiangyu.cn\/?p=22"},"modified":"2024-09-11T21:40:55","modified_gmt":"2024-09-11T13:40:55","slug":"armadillo%e4%bd%bf%e7%94%a8%e4%bb%8b%e7%bb%8d%ef%bc%88%e4%ba%94%ef%bc%89%ef%bc%9aany%ef%bc%8call%ef%bc%8c-is_zero","status":"publish","type":"post","link":"https:\/\/chaixiangyu.cn\/?p=22","title":{"rendered":"Armadillo\u4f7f\u7528\u4ecb\u7ecd\uff08\u4e94\uff09\uff1aany\uff0call\uff0c.is_zero"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">any<\/h1>\n\n\n\n<p>\u7528\u9014\uff1a<em>any\u51fd\u6570\u7528\u4e8e\u5224\u65ad<strong>\u5411\u91cf\u6216\u8005\u77e9\u9635<\/strong>\u4e2d\u4efb\u4f55\u5143\u7d20\u975e\u96f6\u6216\u6ee1\u8db3\u5173\u7cfb\u6761\u4ef6\uff0c\u6ee1\u8db3\u5219\u8fd4\u56detrue\uff0c\u4e0d\u6ee1\u8db3\u5219\u8fd4\u56defalse\u3002<\/em><br>\u7c7b\u578b\uff1a<em>\u666e\u901a\u51fd\u6570<\/em><br>\u8be5\u51fd\u6570\u91cd\u8f7d\u6709any( V )\u3001any( X )\u3001any( X, dim )\u3002<br>1\u3001\u5bf9\u4e8e\u5411\u91cf V\uff0c\u5982\u679c\u5411\u91cf\u7684\u4efb\u4f55\u5143\u7d20\u975e\u96f6\u6216\u6ee1\u8db3\u5173\u7cfb\u6761\u4ef6\uff0c\u5219\u8fd4\u56de true\u3002<br>2\u3001\u5bf9\u4e8e\u77e9\u9635X\u548c<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>dim=0\uff0c\u8fd4\u56de\u4e00\u4e2a\u884c\u5411\u91cf\uff08\u7c7b\u578b\u4e3aurowvec\u6216umat\uff09\uff0c\u6bcf\u4e2a\u5143\u7d20 \uff080 \u6216 1\uff09 \u6307\u793aX\u7684\u76f8\u5e94\u5217\u7684\u4efb\u4f55\u5143\u7d20\u662f\u5426\u975e\u96f6\uff1b<\/li>\n\n\n\n<li>dim=1\uff0c\u8fd4\u56de\u5217\u5411\u91cf\uff08\u7c7b\u578b\u4e3aucolvec\u6216umat\uff09\uff0c\u6bcf\u4e2a\u5143\u7d20 \uff080 \u6216 1\uff09 \u6307\u793aX\u7684\u76f8\u5e94\u884c\u7684\u4efb\u4f55\u5143\u7d20\u662f\u5426\u975e\u96f6\u3002<\/li>\n<\/ul>\n\n\n\n<p>3\u3001dim\u53c2\u6570\u662f\u53ef\u9009\u7684\uff1b\u9ed8\u8ba4\u60c5\u51b5\u4e0bdim=0\u3002<br>4\u3001\u53ef\u4ee5\u4f7f\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26\u4ee3\u66ffV\u6216X\uff0c\u4f8b\u5982A &gt; 0.9\u3002<br>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vec V = randu&lt;vec&gt;(10);\nmat X = randu&lt;mat&gt;(5,5);\n\n\/\/ status1 will be set to true if vector V has any non-zero elements\nbool status1 = any(V);\n\n\/\/ status2 will be set to true if vector V has any elements greater than 0.5\nbool status2 = any(V &gt; 0.5);\n\n\/\/ status3 will be set to true if matrix X has any elements greater than 0.6;\n\/\/ note the use of vectorise()\nbool status3 = any(vectorise(X) &gt; 0.6);\n\n\/\/ generate a row vector indicating which columns of X have elements greater than 0.7\numat A = any(X &gt; 0.7);<\/code><\/pre>\n\n\n\n<p>\u53c2\u8003\uff1aArmadillo\u5e93\u6587\u6863<a href=\"http:\/\/arma.sourceforge.net\/docs.html#any\">any<\/a><br><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">all<\/h1>\n\n\n\n<p>\u7528\u9014\uff1a<em>all\u51fd\u6570\u7528\u4e8e\u5224\u65ad<strong>\u5411\u91cf\u6216\u8005\u77e9\u9635<\/strong>\u4e2d\u6240\u6709\u5143\u7d20\u975e\u96f6\u6216\u6ee1\u8db3\u5173\u7cfb\u6761\u4ef6\uff0c\u6ee1\u8db3\u5219\u8fd4\u56detrue\uff0c\u4e0d\u6ee1\u8db3\u5219\u8fd4\u56defalse\u3002<\/em><br>\u7c7b\u578b\uff1a<em>\u666e\u901a\u51fd\u6570<\/em><br>\u8be5\u51fd\u6570\u91cd\u8f7d\u6709all( V )\u3001all( X )\u3001all( X, dim )\u3002<br>1\u3001\u5bf9\u4e8e\u5411\u91cf V\uff0c\u5982\u679c\u5411\u91cf\u7684\u6240\u6709\u5143\u7d20\u975e\u96f6\u6216\u6ee1\u8db3\u5173\u7cfb\u6761\u4ef6\uff0c\u5219\u8fd4\u56de true\uff1b\u53cd\u4e4b\u8fd4\u56defalse\u3002<br>2\u3001\u5bf9\u4e8e\u77e9\u9635X\u548c<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>dim=0\uff0c\u8fd4\u56de\u4e00\u4e2a\u884c\u5411\u91cf\uff08\u7c7b\u578b\u4e3aurowvec\u6216umat\uff09\uff0c\u6bcf\u4e2a\u5143\u7d20 \uff080 \u6216 1\uff09 \u6307\u793aX\u7684\u76f8\u5e94\u5217\u7684\u6240\u6709\u5143\u7d20\u662f\u5426\u975e\u96f6\uff1b<\/li>\n\n\n\n<li>dim=1\uff0c\u8fd4\u56de\u5217\u5411\u91cf\uff08\u7c7b\u578b\u4e3aucolvec\u6216umat\uff09\uff0c\u6bcf\u4e2a\u5143\u7d20 \uff080 \u6216 1\uff09 \u6307\u793aX\u7684\u76f8\u5e94\u884c\u7684\u6240\u6709\u5143\u7d20\u662f\u5426\u975e\u96f6\u3002<\/li>\n<\/ul>\n\n\n\n<p>3\u3001dim\u53c2\u6570\u662f\u53ef\u9009\u7684\uff1b\u9ed8\u8ba4\u60c5\u51b5\u4e0bdim=0\u3002<br>4\u3001\u53ef\u4ee5\u4f7f\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26\u4ee3\u66ffV\u6216X\uff0c\u4f8b\u5982A &gt; 0.5\u3002<br>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vec V = randu&lt;vec&gt;(10);\nmat X = randu&lt;mat&gt;(5,5);\n\n\/\/ status1 will be set to true if vector V has all non-zero elements\nbool status1 = all(V);\n\n\/\/ status2 will be set to true if vector V has all elements greater than 0.5\nbool status2 = all(V &gt; 0.5);\n\n\/\/ status3 will be set to true if matrix X has all elements greater than 0.6;\n\/\/ note the use of vectorise()\nbool status3 = all(vectorise(X) &gt; 0.6);\n\n\/\/ generate a row vector indicating which columns of X have all elements greater than 0.7\numat A = all(X &gt; 0.7);<\/code><\/pre>\n\n\n\n<p>\u53c2\u8003\uff1aArmadillo\u5e93\u6587\u6863<a href=\"http:\/\/arma.sourceforge.net\/docs.html#all\">all<\/a><br><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">.is_zero<\/h1>\n\n\n\n<p>\u7528\u9014\uff1a<em>.is_zero\u51fd\u6570\u7528\u4e8e\u5224\u65ad<strong>\u77e9\u9635<\/strong>\u4e2d\u6240\u6709\u5143\u7d20\u662f\u5426\u4e3a0\uff0c\u662f\u5219\u8fd4\u56detrue\uff1b\u53cd\u4e4b\u8fd4\u56defalse\u3002<\/em><br>\u7c7b\u578b\uff1a<em>\u666e\u901a\u51fd\u6570<\/em><br>\u8be5\u51fd\u6570\u91cd\u8f7d\u6709.is_zero()\u3001.is_zero( tolerance )\u3002<br>1\u3001\u5bf9\u4e8e\u5177\u6709\u975e\u590d\u6570\u5143\u7d20\u7684\u5bf9\u8c61\uff1a\u5982\u679c\u6bcf\u4e2a\u5143\u7d20\u7684\u7edd\u5bf9\u503c\u2264tolerance\uff0c\u5219\u8fd4\u56detrue\uff1b\u53cd\u4e4b\u8fd4\u56defalse\u3002<br>2\u3001\u5bf9\u4e8e\u5177\u6709\u590d\u6570\u5143\u7d20\u7684\u5bf9\u8c61\uff1a\u5982\u679c\u6bcf\u4e2a\u5143\u7d20\u7684\u6bcf\u4e2a\u5206\u91cf\uff08\u5b9e\u90e8\u548c\u865a\u90e8\uff09\u7684\u7edd\u5bf9\u503c\u2264tolerance\uff0c\u5219\u8fd4\u56detrue\uff1b\u53cd\u4e4b\u8fd4\u56defalse\u3002<br>3\u3001\u53c2\u6570tolerance\u662f\u53ef\u9009\u7684\uff1b\u9ed8\u8ba4\u60c5\u51b5\u4e0btolerance = 0\u3002<br>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mat A = zeros&lt;mat&gt;(5,5);\n\nA(0,0) = datum::eps;\n\ncout &lt;&lt; A.is_zero()           &lt;&lt; endl;\ncout &lt;&lt; A.is_zero(datum::eps) &lt;&lt; endl;<\/code><\/pre>\n\n\n\n<p>\u53c2\u8003\uff1aArmadillo\u5e93\u6587\u6863<a href=\"http:\/\/arma.sourceforge.net\/docs.html#is_zero\">.is_zero<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>any \u7528\u9014\uff1aany\u51fd\u6570\u7528\u4e8e\u5224\u65ad\u5411\u91cf\u6216\u8005\u77e9\u9635\u4e2d\u4efb\u4f55\u5143\u7d20\u975e\u96f6\u6216\u6ee1\u8db3\u5173\u7cfb\u6761\u4ef6\uff0c\u6ee1\u8db3\u5219\u8fd4\u56detrue\uff0c\u4e0d\u6ee1\u8db3\u5219\u8fd4\u56defa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-algorithm"],"_links":{"self":[{"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22"}],"version-history":[{"count":1,"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=\/wp\/v2\/posts\/22\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chaixiangyu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}