1 |
<span role="presentation"><span class="cm-keyword">import</span> <span class="cm-variable">numpy</span> <span class="cm-keyword">as</span> <span class="cm-variable">np</span></span> |
1 |
1 |
<span role="presentation"><span class="cm-comment"># Numpy配列xを生成</span></span> |
1 |
<span role="presentation"><span class="cm-variable">x</span> = <span class="cm-variable">np</span>.<span class="cm-property">arange</span>(<span class="cm-number">20</span>)</span> |
1 |
<span role="presentation"><span class="cm-variable">x</span> = <span class="cm-variable">x</span>.<span class="cm-property">reshape</span>(<span class="cm-number">4</span>, <span class="cm-number">5</span>)</span> |
1 2 |
<span role="presentation"> >>></span> |
1 |
1 2 3 4 |
[[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19]] |
1 2 3 4 |
<span role="presentation"> </span> |
1 |
<span role="presentation"><span class="cm-comment"># xの全ての要素に10を足す</span></span> |
1 2 3 4 5 6 7 8 9 10 11 12 |
<span role="presentation"><span class="cm-variable">x</span> = <span class="cm-variable">x</span> <span class="cm-operator">+</span> <span class="cm-number">10 >>> [[10 11 12 13 14] [15 16 17 18 19] [20 21 22 23 24] [25 26 27 28 29]] </span></span> |
1 |
1 |
<span role="presentation"></span> |
1 |
<span role="presentation"><span class="cm-comment"># 0から4の整数値をもつ1×4のNumpy配列yを生成</span></span> |
1 |
<span role="presentation"><span class="cm-variable">y</span> = <span class="cm-variable">np</span>.<span class="cm-property">array</span>([<span class="cm-variable">np</span>.<span class="cm-property">arange</span>(<span class="cm-number">5</span>)])</span> |
1 |
<span role="presentation">>>>[[0 1 2 3 4]]</span> |
1 |
1 |
<span role="presentation"></span> |
1 |
<span role="presentation"><span class="cm-comment"># xのn番目の列のすべての行からnだけ引く</span></span> |
1 |
<span role="presentation"><span class="cm-variable">x</span> = <span class="cm-variable">x</span> <span class="cm-operator">-</span> <span class="cm-variable">y</span></span> |