{"id":1521,"date":"2023-05-21T08:33:29","date_gmt":"2023-05-21T08:33:29","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=1521"},"modified":"2023-05-21T08:33:29","modified_gmt":"2023-05-21T08:33:29","slug":"explain-slicing-of-matrix-with-example","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/21\/explain-slicing-of-matrix-with-example\/","title":{"rendered":"Explain slicing of matrix with example"},"content":{"rendered":"\n<p>Slicing will return you the elements from the matrix based on the start \/end index given.<\/p>\n\n\n\n<p><strong>The syntax for slicing is:<\/strong><\/p>\n\n\n\n<p><code>[start:end]<\/code><\/p>\n\n\n\n<ul>\n<li>If the start index is not given, it is considered as 0. For example [:5], it means as [0:5].<\/li>\n\n\n\n<li>If the end is not passed, it will take as the length of the array.<\/li>\n\n\n\n<li>If the start\/end has negative values, it will the slicing will be done from the end of the array.<\/li>\n<\/ul>\n\n\n\n<p>Before we work on slicing on a matrix, let us first understand how to apply slice on a simple array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np\n\narr = np.array([2,4,6,8,10,12,14,16])\nprint(arr[3:6]) # will print the elements from 3 to 5\nprint(arr[:5]) # will print the elements from 0 to 4\nprint(arr[2:]) # will print the elements from 2 to length of the array.\nprint(arr[-5:-1]) # will print from the end i.e. -5 to -2\nprint(arr[:-1]) # will print from end i.e. 0 to -2<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Slicing will return you the elements from the matrix based on the start \/end index&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1521"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=1521"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1521\/revisions"}],"predecessor-version":[{"id":1522,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1521\/revisions\/1522"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=1521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=1521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=1521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}