2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -10,14 +10,14 @@
In [1]:
```
```py
from numpy import *
```
使用前一定要先导入 Numpy 包,导入的方法有以下几种:
```
```py
import numpy
import numpy as np
from numpy import *
@@ -29,12 +29,12 @@ import numpy
In [2]:
```
```py
%pylab
```
```
```py
Using matplotlib backend: Qt4Agg
Populating the interactive namespace from numpy and matplotlib
@@ -46,13 +46,13 @@ Populating the interactive namespace from numpy and matplotlib
In [3]:
```
```py
a = [1, 2, 3, 4]
a + 1
```
```
```py
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-068856d2a224> in <module>()
@@ -66,7 +66,7 @@ TypeError: can only concatenate list (not "int") to list
In [4]:
```
```py
a = array(a)
a
@@ -74,7 +74,7 @@ a
Out[4]:
```
```py
array([1, 2, 3, 4])
```
@@ -82,14 +82,14 @@ array([1, 2, 3, 4])
In [5]:
```
```py
a + 1
```
Out[5]:
```
```py
array([2, 3, 4, 5])
```
@@ -97,7 +97,7 @@ array([2, 3, 4, 5])
In [6]:
```
```py
b = array([2, 3, 4, 5])
a + b
@@ -105,7 +105,7 @@ a + b
Out[6]:
```
```py
array([3, 5, 7, 9])
```
@@ -113,14 +113,14 @@ array([3, 5, 7, 9])
In [7]:
```
```py
a * b
```
Out[7]:
```
```py
array([ 2, 6, 12, 20])
```
@@ -128,14 +128,14 @@ array([ 2, 6, 12, 20])
In [8]:
```
```py
a ** b
```
Out[8]:
```
```py
array([ 1, 8, 81, 1024])
```
@@ -145,14 +145,14 @@ array([ 1, 8, 81, 1024])
In [9]:
```
```py
a[0]
```
Out[9]:
```
```py
1
```
@@ -160,14 +160,14 @@ Out[9]:
In [10]:
```
```py
a[:2]
```
Out[10]:
```
```py
array([1, 2])
```
@@ -175,14 +175,14 @@ array([1, 2])
In [11]:
```
```py
a[-2:]
```
Out[11]:
```
```py
array([3, 4])
```
@@ -190,14 +190,14 @@ array([3, 4])
In [12]:
```
```py
a[:2] + a[-2:]
```
Out[12]:
```
```py
array([4, 6])
```
@@ -207,14 +207,14 @@ array([4, 6])
In [13]:
```
```py
a.shape
```
Out[13]:
```
```py
(4L,)
```
@@ -222,7 +222,7 @@ Out[13]:
In [14]:
```
```py
a.shape = 2,2
a
@@ -230,7 +230,7 @@ a
Out[14]:
```
```py
array([[1, 2],
[3, 4]])
```
@@ -241,14 +241,14 @@ array([[1, 2],
In [15]:
```
```py
a + a
```
Out[15]:
```
```py
array([[2, 4],
[6, 8]])
```
@@ -257,14 +257,14 @@ array([[2, 4],
In [16]:
```
```py
a * a
```
Out[16]:
```
```py
array([[ 1, 4],
[ 9, 16]])
```
@@ -275,7 +275,7 @@ linspace 用来生成一组等间隔的数据:
In [17]:
```
```py
a = linspace(0, 2*pi, 21)
%precision 3
a
@@ -284,7 +284,7 @@ a
Out[17]:
```
```py
array([ 0\. , 0.314, 0.628, 0.942, 1.257, 1.571, 1.885, 2.199,
2.513, 2.827, 3.142, 3.456, 3.77 , 4.084, 4.398, 4.712,
5.027, 5.341, 5.655, 5.969, 6.283])
@@ -294,7 +294,7 @@ array([ 0\. , 0.314, 0.628, 0.942, 1.257, 1.571, 1.885, 2.199,
In [18]:
```
```py
b = sin(a)
b
@@ -302,7 +302,7 @@ b
Out[18]:
```
```py
array([ 0.000e+00, 3.090e-01, 5.878e-01, 8.090e-01, 9.511e-01,
1.000e+00, 9.511e-01, 8.090e-01, 5.878e-01, 3.090e-01,
1.225e-16, -3.090e-01, -5.878e-01, -8.090e-01, -9.511e-01,
@@ -314,7 +314,7 @@ array([ 0.000e+00, 3.090e-01, 5.878e-01, 8.090e-01, 9.511e-01,
In [19]:
```
```py
%matplotlib inline
plot(a, b)
@@ -322,7 +322,7 @@ plot(a, b)
Out[19]:
```
```py
[<matplotlib.lines.Line2D at 0xa128ba8>]
```
@@ -490,14 +490,14 @@ HzC+mVy4trE1AAAAAElFTkSuQmCC
In [20]:
```
```py
b >= 0
```
Out[20]:
```
```py
array([ True, True, True, True, True, True, True, True, True,
True, True, False, False, False, False, False, False, False,
False, False, False], dtype=bool)
@@ -505,7 +505,7 @@ array([ True, True, True, True, True, True, True, True, True,
In [21]:
```
```py
mask = b >= 0
```
@@ -514,14 +514,14 @@ mask = b >= 0
In [22]:
```
```py
plot(a[mask], b[mask], 'ro')
```
Out[22]:
```
```py
[<matplotlib.lines.Line2D at 0xa177be0>]
```