{"id":289043,"date":"2018-09-06T13:00:03","date_gmt":"2018-09-06T09:00:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=289043"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2018-09-06T09:00:03","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=289043","title":{"rendered":"Python \u0438 DataScience: \u0438\u0437\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Numpy"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/company\/skillbox\/blog\/422423\/\" class=\"post__text post__text-html js-mediator-article\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/00c\/384\/015\/00c3840151065f40c886c6b28c3e4091.png\"><\/p>\n<p>  <b>\u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430:<\/b> \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0420\u0430\u043a\u0448\u0438\u0442\u0430 \u0412\u0430\u0441\u0443\u0434\u0435\u0432\u0430, \u0434\u0430\u0432\u043d\u043e \u0438 \u043f\u043b\u043e\u0442\u043d\u043e \u0438\u0437\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e DataScience \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u043d\u0435\u0439 \u044f\u0437\u044b\u043a\u0430 Python. \u0410\u0432\u0442\u043e\u0440 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e \u043c\u043e\u0449\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Numpy, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>  Numpy \u2014 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f Python. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e. \u041e\u043d\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c Python \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043d\u0435\u0439 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 Numpy, \u0438 \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c; \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u0421\u0442\u0430\u0442\u044c\u044f \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0437\u0443\u0447\u0430\u0442\u044c Numpy, \u0432\u0441\u0442\u0443\u043f\u0430\u044f \u0432 \u0434\u0438\u0432\u043d\u044b\u0439 \u043c\u0438\u0440 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438 \u0432 Python.<br \/>   <a name=\"habracut\"><\/a>  <\/p>\n<blockquote><p><b>Skillbox \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442:<\/b> \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0443\u0440\u0441 <a href=\"https:\/\/skillbox.ru\/python\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=PTNDEV&amp;utm_content=articles&amp;utm_term=pythonanddatascience\">\u00abPython-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441 \u043d\u0443\u043b\u044f\u00bb<\/a>.<br \/>  <b>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c:<\/b> <i>\u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u0425\u0430\u0431\u0440\u0430\u00bb \u2014 \u0441\u043a\u0438\u0434\u043a\u0430 10 000 \u0440\u0443\u0431\u043b\u0435\u0439 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u0443\u0440\u0441 Skillbox \u043f\u043e \u043f\u0440\u043e\u043c\u043e\u043a\u043e\u0434\u0443 \u00ab\u0425\u0430\u0431\u0440\u00bb.<\/i><\/p><\/blockquote>\n<p>  <\/p>\n<h3>\u0418\u043c\u043f\u043e\u0440\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/h3>\n<p>  <\/p>\n<pre><code class=\"python\">import numpy as np<\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c Python, \u0447\u0442\u043e np \u2014 \u044d\u0442\u043e \u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0441 \u0434\u043b\u044f Numpy, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043f\u0440\u0435\u0434\u044c.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 python \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 np.<\/p>\n<pre><code class=\"python\"># python array a = [1,2,3,4,5,6,7,8,9]   # numpy array A = np.array([1,2,3,4,5,6,7,8,9])<\/code><\/pre>\n<p>  \u0411\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435 \u043d\u0435\u0442.<\/p>\n<pre><code class=\"python\">print(a) print(A) ==================================================================== [1, 2, 3, 4, 5, 6, 7, 8, 9] [1 2 3 4 5 6 7 8 9]<\/code><\/pre>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 numpy \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e? \u041e\u0442\u0432\u0435\u0442 \u2014 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e np \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h3>np.arange()<\/h3>\n<p>  <\/p>\n<pre><code class=\"python\">np.arange(0,10,2) ==================================================================== array([0, 2, 4, 6, 8])<\/code><\/pre>\n<p>  ([start],stop,[step]) \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u0435\u0442 \u0446\u0438\u0444\u0440\u044b. \u0412\u043e\u0442 \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0434\u043b\u044f \u043c\u0430\u0448\u0438\u043d\u044b.<\/p>\n<p>  \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c np-\u0441\u043f\u0438\u0441\u043e\u043a, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 0 \u0434\u043e 10, \u043d\u043e \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c 10, \u043f\u043b\u044e\u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0446\u0438\u0444\u0440\u044b \u043d\u0430 2 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u0442 \u0447\u0442\u043e:<br \/>  array([0, 2, 4, 6, 8])<\/p>\n<p>  \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0446\u0438\u0444\u0440\u0430 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a.<\/p>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">np.arange(2,29,5) ==================================================================== array([2, 7, 12, 17, 22, 27])<\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u0438\u043b\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u0439\u0442\u0435, \u043a\u043e\u0433\u0434\u0430 \u044f \u0433\u043e\u0432\u043e\u0440\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: \u00ab\u0424\u043e\u0440\u043c\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u2014 2*3\u00bb. \u0412\u0441\u0435 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0438\u0442\u043e\u0433\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">array([2, 7, 12],       [17, 22, 27])<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u0430\u043a\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435, \u043a\u0430\u043a shape \u0434\u043b\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 np \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. Shape \u0437\u0434\u0435\u0441\u044c \u2014 \u0430\u0442\u0440\u0438\u0431\u0443\u0442. \u041f\u0440\u0438\u043c\u0435\u0440 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u043d\u0438\u0436\u0435.<\/p>\n<pre><code class=\"python\">A = [1, 2, 3, 4, 5, 6, 7, 8, 9] A.shape ==================================================================== (9,)<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u0437 \u0447\u0438\u0441\u0435\u043b, \u0433\u0434\u0435 \u0432 \u0440\u044f\u0434\u0443 \u0432\u0441\u0435\u0433\u043e 9 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 1*9, \u043d\u0435 \u0442\u0430\u043a \u043b\u0438?<\/p>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0434\u0430, \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e reshape() \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432 \u0438\u0433\u0440\u0443. \u042d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0442\u0430\u043a, \u043a\u0430\u043a \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043d\u0430\u043c.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f reshape() \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435.<\/p>\n<pre><code class=\"python\">A = [1, 2, 3, 4, 5, 6, 7, 8, 9] A.reshape(1,9) ==================================================================== array([[1, 2, 3, 4, 5, 6, 7, 8, 9]])<\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e reshape \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443. \u041d\u0430 \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0434\u0432\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043a\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435. [[1, 2, 3, 4, 5, 6, 7, 8, 9]] \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 [1, 2, 3, 4, 5, 6, 7, 8, 9].<\/p>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">B = [1, 2, 3, 4, 5, 6, 7, 8, 9] B.reshape(3,3) ==================================================================== array([[1, 2, 3],        [4, 5, 6],        [7, 8, 9]])<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 shape \u0434\u043b\u044f B, \u0442\u043e \u0438\u043c \u0431\u0443\u0434\u0435\u0442 (3,3):<\/p>\n<pre><code class=\"python\">B.shape ==================================================================== (3,3)<\/code><\/pre>\n<p>  <\/p>\n<h3>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a np.zeros()<\/h3>\n<p>  \u0427\u0442\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435?<\/p>\n<pre><code class=\"python\">np.zeros((4,3)) ==================================================================== ???????????<\/code><\/pre>\n<p>  \u0418\u043c\u0435\u043d\u043d\u043e: \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u0434\u0430\u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 3*4, \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u0430\u044f \u043d\u0443\u043b\u044f\u043c\u0438. \u0412\u043e\u0442 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"python\">np.zeros((4,3)) ==================================================================== array([[0., 0., 0.],        [0., 0., 0.],        [0., 0., 0.],        [0., 0., 0.]])<\/code><\/pre>\n<p>  np.zeros((n,m)) \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 n*m, \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u0443\u044e \u043d\u0443\u043b\u044f\u043c\u0438. \u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<h3>\u0410 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 np.eye()?<\/h3>\n<p>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u043c\u0438.<\/p>\n<pre><code class=\"python\">np.eye(5) ==================================================================== array([[1., 0., 0., 0., 0.],        [0., 1., 0., 0., 0.],        [0., 0., 1., 0., 0.],        [0., 0., 0., 1., 0.],        [0., 0., 0., 0., 1.]])<\/code><\/pre>\n<p>  <\/p>\n<h3>\u041a\u0430\u043a \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u0434\u0432\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b?<\/h3>\n<p>  \u041d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c: \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f np.dot(), \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u2014 \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043d\u0435\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u0430\u0442\u0440\u0438\u0446 (\u0441\u0430\u043c\u043e\u0435 \u043e\u0431\u044b\u043a\u043d\u043e\u0432\u0435\u043d\u043d\u043e\u0435).<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440: A = (2,3) &amp; B = (3,2). \u0417\u0434\u0435\u0441\u044c \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u0410 \u2014 3. \u0427\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0412 \u2014 3. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<pre><code class=\"python\"># generate an identity matrix of (3 x 3) I = np.eye(3) I ==================================================================== array([[1., 0., 0.],        [0., 1., 0.],        [0., 0., 1.]])  # generate another (3 x 3) matrix to be multiplied. D = np.arange(1,10).reshape(3,3) D ==================================================================== array([[1, 2, 3],        [4, 5, 6],        [7, 8, 9]])<\/code><\/pre>\n<p>  \u041c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043a \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044e. \u0414\u0430\u043b\u0435\u0435 \u2014 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u043c.<\/p>\n<pre><code class=\"python\"># perform actual dot product. M = np.dot(D,I) M ==================================================================== array([[1., 2., 3.],        [4., 5., 6.],        [7., 8., 9.]])<\/code><\/pre>\n<p>  <\/p>\n<h3>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0443<\/h3>\n<p>  <\/p>\n<pre><code class=\"python\"># add all the elements of matrix. sum_val = np.sum(M) sum_val ==================================================================== 45.0<\/code><\/pre>\n<p>  np.sum() \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0443.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430.<\/p>\n<p>  <b>1. \u0421\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c.<\/b><\/p>\n<pre><code class=\"python\"># sum along the rows np.sum(M,axis=1) ==================================================================== array([ 6., 15., 24.])<\/code><\/pre>\n<p>  6 \u2014 \u0441\u0443\u043c\u043c\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 (1, 2, 3).<br \/>  15 \u2014 \u0432\u0442\u043e\u0440\u043e\u0439 (4, 5, 6).<br \/>  24 \u2014 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 (7, 8, 9).<\/p>\n<p>  <b>2. \u0421\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c.<\/b><\/p>\n<pre><code class=\"python\"># sum along the cols np.sum(M,axis=0) ==================================================================== array([12., 15., 18.])<\/code><\/pre>\n<p>  12 \u2014 \u0441\u0443\u043c\u043c\u0430 \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443 (1, 4, 7).<br \/>  15 \u2014 \u043f\u043e \u0432\u0442\u043e\u0440\u043e\u043c\u0443 (2, 5, 7).<br \/>  18 \u2014 \u043f\u043e \u0442\u0440\u0435\u0442\u044c\u0435\u043c\u0443 (3, 6, 9).<\/p>\n<p>  \u041d\u0438\u0436\u0435 \u2014 \u0432\u0438\u0434\u0435\u043e, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0435 \u0430\u0432\u0442\u043e\u0440\u043e\u043c, \u0433\u0434\u0435 \u0432\u0441\u0435, \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0440\u0430\u0437, \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e.<\/p>\n<div class=\"oembed\">\n<div>\n<div style=\"left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.2493%;\"><iframe src=\"https:\/\/www.youtube.com\/embed\/LPcgo-SFXWU?rel=0&amp;showinfo=1&amp;hl=en-US\" style=\"border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;\" allowfullscreen scrolling=\"no\"><\/iframe><\/div>\n<\/div>\n<\/div>\n<p>  <\/p>\n<blockquote><p><b>Skillbox \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442:<\/b><\/p>\n<ul>\n<li>\u041e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441<a href=\"https:\/\/skillbox.ru\/python\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=PTNDEV&amp;utm_content=articles&amp;utm_term=pythonanddatascience\">\u00abPython-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441 \u043d\u0443\u043b\u044f\u00bb<\/a>.<\/li>\n<li>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u043e\u0434\u043e\u0432\u043e\u0439 \u043a\u0443\u0440\u0441 <a href=\"https:\/\/skillbox.ru\/php\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=PHPDEV&amp;utm_content=articles&amp;utm_term=pythonanddatascience\">\u00abPHP-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441 \u043d\u0443\u043b\u044f \u0434\u043e PRO\u00bb<\/a>.<\/li>\n<li>\u041e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441 <a href=\"https:\/\/skillbox.ru\/java\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=JAVDEV&amp;utm_content=articles&amp;utm_term=pythonanddatascience\">\u00ab\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f Java-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u00bb<\/a>.<\/li>\n<\/ul>\n<\/blockquote>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/422423\/\"> https:\/\/habr.com\/post\/422423\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/company\/skillbox\/blog\/422423\/\" class=\"post__text post__text-html js-mediator-article\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/00c\/384\/015\/00c3840151065f40c886c6b28c3e4091.png\"><\/p>\n<p>  <b>\u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430:<\/b> \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0420\u0430\u043a\u0448\u0438\u0442\u0430 \u0412\u0430\u0441\u0443\u0434\u0435\u0432\u0430, \u0434\u0430\u0432\u043d\u043e \u0438 \u043f\u043b\u043e\u0442\u043d\u043e \u0438\u0437\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e DataScience \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u043d\u0435\u0439 \u044f\u0437\u044b\u043a\u0430 Python. \u0410\u0432\u0442\u043e\u0440 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e \u043c\u043e\u0449\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Numpy, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>  Numpy \u2014 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f Python. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e. \u041e\u043d\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c Python \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043d\u0435\u0439 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 Numpy, \u0438 \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c; \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u0421\u0442\u0430\u0442\u044c\u044f \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0437\u0443\u0447\u0430\u0442\u044c Numpy, \u0432\u0441\u0442\u0443\u043f\u0430\u044f \u0432 \u0434\u0438\u0432\u043d\u044b\u0439 \u043c\u0438\u0440 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438 \u0432 Python.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-289043","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/289043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=289043"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/289043\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=289043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=289043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=289043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}