{"id":27259,"date":"2021-05-15T11:16:20","date_gmt":"2021-05-15T15:16:20","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/valarray-slice-programming-code-examples-c-valarray\/"},"modified":"2021-05-15T11:16:20","modified_gmt":"2021-05-15T15:16:20","slug":"valarray-slice-programming-code-examples-c-valarray","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=27259","title":{"rendered":"valarray slice #Programming Code Examples #C++ #Valarray"},"content":{"rendered":"<p>\/* The following code example is taken from the book<br \/>\n * &quot;The C++ Standard Library &#8211; A Tutorial and Reference&quot;<br \/>\n * by Nicolai M. Josuttis, Addison-Wesley, 1999<br \/>\n *<br \/>\n * (C) Copyright Nicolai M. Josuttis 1999.<br \/>\n * Permission to copy, use, modify, sell and distribute this software<br \/>\n * is granted provided this copyright notice appears in all copies.<br \/>\n * This software is provided &quot;as is&quot; without express or implied<br \/>\n * warranty, and with no claim as to its suitability for any purpose.<br \/>\n *\/ <\/p>\n<pre style='font-size:15px'>\n#include &lt;iostream&gt;\n#include &lt;valarray&gt;\nusing namespace std;\n\n\/\/ print valarray line-by-line\ntemplate&lt;class T&gt;\nvoid printValarray (const valarray&lt;T&gt;&amp; va, int num)\n{\n    for (int i=0; i&lt;va.size()\/num; ++i) {\n        for (int j=0; j&lt;num; ++j) {\n            cout &lt;&lt; va[i*num+j] &lt;&lt; ' ';\n        }\n        cout &lt;&lt; endl;\n    }\n    cout &lt;&lt; endl;\n}\n\nint main()\n{\n    \/* valarray with 12 elements\n     * - four rows\n     * - three columns\n     *\/\n    valarray&lt;double&gt; va(12);\n\n    \/\/ fill valarray with values\n    for (int i=0; i&lt;12; i++) {\n        va[i] = i;\n    }\n\n    printValarray (va, 3);\n\n    \/\/ first column = second column raised to the third column\n    va[slice(0,4,3)] = pow (valarray&lt;double&gt;(va[slice(1,4,3)]),\n                            valarray&lt;double&gt;(va[slice(2,4,3)]));\n\n    printValarray (va, 3);\n\n    \/\/ create valarray with three times the third element of va\n    valarray&lt;double&gt; vb(va[slice(2,4,0)]);\n\n    \/\/ multiply the third column by the elements of vb\n    va[slice(2,4,3)] *= vb;\n\n    printValarray (va, 3);\n\n    \/\/ print the square root of the elements in the second row\n    \/\/printValarray (sqrt(valarray&lt;double&gt;(va[slice(3,3,1)])));\n\n    \/\/ double the elements in the third row\n    va[slice(2,4,3)] = valarray&lt;double&gt;(va[slice(2,4,3)]) * 2.0;\n\n    printValarray (va, 3);\n}\n\n\/*\n0 1 2\n3 4 5\n6 7 8\n9 10 11\n\n1 1 2\n1024 4 5\n5.7648e+006 7 8\n1e+011 10 11\n\n1 1 4\n1024 4 10\n5.7648e+006 7 16\n1e+011 10 22\n\n1 1 8\n1024 4 20\n5.7648e+006 7 32\n1e+011 10 44\n\n\n *\/\n\n<\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10188<br \/> Categories:Programming Code Examples, C++, Valarray<br \/>Tags:C++Valarray<br \/> Post Data:2017-01-02 16:04:23<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* The following code example is taken from the book * &quot;The C++ Standard Library &#8211; A Tutorial and Reference&quot; * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=27259\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-27259","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10089,"url":"http:\/\/bangla.sitestree.com\/?p=10089","url_meta":{"origin":27259,"position":0},"title":"valarray with double value inside","author":"","date":"July 29, 2015","format":false,"excerpt":"\/* The following code example is taken from the book \u00a0* \"The C++ Standard Library - A Tutorial and Reference\" \u00a0* by Nicolai M. Josuttis, Addison-Wesley, 1999 \u00a0* \u00a0* (C) Copyright Nicolai M. Josuttis 1999. \u00a0* Permission to copy, use, modify, sell and distribute this software \u00a0* is granted provided\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":62213,"url":"http:\/\/bangla.sitestree.com\/?p=62213","url_meta":{"origin":27259,"position":1},"title":"valarray with double value inside #Programming Code Examples #C++ #Valarray","author":"Author-Check- Article-or-Video","date":"May 15, 2021","format":false,"excerpt":"\/* The following code example is taken from the book * \"The C++ Standard Library - A Tutorial and Reference\" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10073,"url":"http:\/\/bangla.sitestree.com\/?p=10073","url_meta":{"origin":27259,"position":2},"title":"valarray slice","author":"","date":"July 27, 2015","format":false,"excerpt":"\/* The following code example is taken from the book * \"The C++ Standard Library - A Tutorial and Reference\" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided\u2026","rel":"","context":"In &quot;C++ \u0964 \u09b8\u09bf \u09aa\u09cd\u09b2\u09be\u09b8 \u09aa\u09cd\u09b2\u09be\u09b8&quot;","block_context":{"text":"C++ \u0964 \u09b8\u09bf \u09aa\u09cd\u09b2\u09be\u09b8 \u09aa\u09cd\u09b2\u09be\u09b8","link":"http:\/\/bangla.sitestree.com\/?cat=1439"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10070,"url":"http:\/\/bangla.sitestree.com\/?p=10070","url_meta":{"origin":27259,"position":3},"title":"Print minimum, maximum, and sum of the valarray","author":"","date":"July 27, 2015","format":false,"excerpt":"\/* The following code example is taken from the book * \"The C++ Standard Library - A Tutorial and Reference\" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10556,"url":"http:\/\/bangla.sitestree.com\/?p=10556","url_meta":{"origin":27259,"position":4},"title":"Print three-dimensional valarray line-by-line","author":"","date":"August 29, 2015","format":false,"excerpt":"\/* The following code example is taken from the book \u00a0* \"The C++ Standard Library - A Tutorial and Reference\" \u00a0* by Nicolai M. Josuttis, Addison-Wesley, 1999 \u00a0* \u00a0* (C) Copyright Nicolai M. Josuttis 1999. \u00a0* Permission to copy, use, modify, sell and distribute this software \u00a0* is granted provided\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10550,"url":"http:\/\/bangla.sitestree.com\/?p=10550","url_meta":{"origin":27259,"position":5},"title":"Valarray Example","author":"","date":"August 29, 2015","format":false,"excerpt":"\/* The following code example is taken from the book \u00a0* \"The C++ Standard Library - A Tutorial and Reference\" \u00a0* by Nicolai M. Josuttis, Addison-Wesley, 1999 \u00a0* \u00a0* (C) Copyright Nicolai M. Josuttis 1999. \u00a0* Permission to copy, use, modify, sell and distribute this software \u00a0* is granted provided\u2026","rel":"","context":"In &quot;Ajax&quot;","block_context":{"text":"Ajax","link":"http:\/\/bangla.sitestree.com\/?cat=1418"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27259"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27259\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27259"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}