File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 31, in recsum

value = n - recsum(n + 1)


File "/Users/progprim/Desktop/lecture07.py", line 28, in recsum

if n == 1:


RecursionError: maximum recursion depth exceeded in comparison



In [44]: runfile('/Users/progprim/Desktop/lecture07.py', wdir='/Users/progprim/Desktop')


In [45]: recsum(2)

Out[45]: 3


In [46]: recsum(3)

Out[46]: 6


In [47]: recsum(4)

Out[47]: 10


In [48]: import numpy as np


In [49]: a = np.array([1, 4, 10])


In [50]: type(a)

Out[50]: numpy.ndarray


In [51]: print(a)

[ 1 4 10]


In [52]: a

Out[52]: array([ 1, 4, 10])


In [53]: a * 2

Out[53]: array([ 2, 8, 20])


In [54]: a ** 3

Out[54]: array([ 1, 64, 1000])


In [55]: np.exp(a)

Out[55]: array([ 2.71828183e+00, 5.45981500e+01, 2.20264658e+04])


In [56]: B = np.array([[0, 1.5], [10, 12]])


In [57]: B

Out[57]:

array([[ 0. , 1.5],

[ 10. , 12. ]])


In [58]: a.shape

Out[58]: (3,)


In [59]: B.shape

Out[59]: (2, 2)


In [60]: B

Out[60]:

array([[ 0. , 1.5],

[ 10. , 12. ]])


In [61]: B.shape

Out[61]: (2, 2)


In [62]: B.shape = (4,)


In [63]: B

Out[63]: array([ 0. , 1.5, 10. , 12. ])


In [64]: a.size

Out[64]: 3


In [65]: B.size

Out[65]: 4


In [66]: a.nbytes

Out[66]: 24


In [67]: B.nbytes

Out[67]: 32


In [68]: a.dtype

Out[68]: dtype('int64')


In [69]: a

Out[69]: array([ 1, 4, 10])


In [70]: B.dtype

Out[70]: dtype('float64')


In [71]: c = np.array([0, 1, 2, 3], np.float)


In [72]: c

Out[72]: array([ 0., 1., 2., 3.])


In [73]: np.zeros((2, 3))

Out[73]:

array([[ 0., 0., 0.],

[ 0., 0., 0.]])


In [74]: np.zeros((2, 3)) + 10

Out[74]:

array([[ 10., 10., 10.],

[ 10., 10., 10.]])


In [75]: d = np.zeros((2, 3)) + 10


In [76]: d[0, 1] = 20


In [77]: d

Out[77]:

array([[ 10., 20., 10.],

[ 10., 10., 10.]])


In [78]: d = np.ones((2, 3))


In [79]: d

Out[79]:

array([[ 1., 1., 1.],

[ 1., 1., 1.]])


In [80]: np.eye(4)

Out[80]:

array([[ 1., 0., 0., 0.],

[ 0., 1., 0., 0.],

[ 0., 0., 1., 0.],

[ 0., 0., 0., 1.]])


In [81]: a

Out[81]: array([ 1, 4, 10])


In [82]: len(a)

Out[82]: 3


In [83]: B

Out[83]: array([ 0. , 1.5, 10. , 12. ])


In [84]: B.shape = 2, 2


In [85]: B

Out[85]:

array([[ 0. , 1.5],

[ 10. , 12. ]])


In [86]: len(B)

Out[86]: 2


In [87]: B.shape

Out[87]: (2, 2)


In [88]: a.shpe

Traceback (most recent call last):


File "<ipython-input-88-651ee044f607>", line 1, in <module>

a.shpe


AttributeError: 'numpy.ndarray' object has no attribute 'shpe'



In [89]: a.shape

Out[89]: (3,)


In [90]: a.T

Out[90]: array([ 1, 4, 10])


In [91]: a

Out[91]: array([ 1, 4, 10])


In [92]: B

Out[92]:

array([[ 0. , 1.5],

[ 10. , 12. ]])


In [93]: B[0][1]

Out[93]: 1.5


In [94]: B[0, 1]

Out[94]: 1.5


In [95]: np.arange(10)

Out[95]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])


In [96]: np.arange(5, 200, 20)

Out[96]: array([ 5, 25, 45, 65, 85, 105, 125, 145, 165, 185])


In [97]: np.arange(5, 6, 0.1)

Out[97]: array([ 5. , 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9])


In [98]: np.linspace(0, 5, 6)

Out[98]: array([ 0., 1., 2., 3., 4., 5.])


In [99]: f = np.linspace(0, 11, 10)


In [100]: f

Out[100]:

array([ 0. , 1.22222222, 2.44444444, 3.66666667,

4.88888889, 6.11111111, 7.33333333, 8.55555556,

9.77777778, 11. ])


In [101]: f = np.linspace(0, 10, 11)


In [102]: f

Out[102]: array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])


In [103]: f[5:]

Out[103]: array([ 5., 6., 7., 8., 9., 10.])


In [104]: f[-1]

Out[104]: 10.0


In [105]: f[-2:]

Out[105]: array([ 9., 10.])


In [106]: f[0:10:1]

Out[106]: array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])


In [107]: f[0:10:2]

Out[107]: array([ 0., 2., 4., 6., 8.])


In [108]: f[::2]

Out[108]: array([ 0., 2., 4., 6., 8., 10.])


In [109]: f[::-2]

Out[109]: array([ 10., 8., 6., 4., 2., 0.])


In [110]: f[::-1]

Out[110]: array([ 10., 9., 8., 7., 6., 5., 4., 3., 2., 1., 0.])


In [111]: f[:]

Out[111]: array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])


In [112]: t = np.arange(0, 10*np.pi, 0.01)


In [113]: t.shape

Out[113]: (3142,)


In [114]: t.nbytes

Out[114]: 25136


In [115]: y = np.cos(t)


In [116]: y.shape

Out[116]: (3142,)


In [117]: import pylab


In [118]: pylab.plot(t, y)

Out[118]: [<matplotlib.lines.Line2D at 0x11975a390>]


In [119]: pylab.plot(t, y**4)

Out[119]: [<matplotlib.lines.Line2D at 0x11cb2ada0>]


In [120]: pylab.xlabel('t')

Out[120]: <matplotlib.text.Text at 0x11a0c2828>


In [121]: %matplotlib qt


In [122]: pylab.plot(t, y)

Out[122]: [<matplotlib.lines.Line2D at 0x1197b4a58>]


In [123]: pylab.show()


In [123]:


In [124]: %matplotlib inline


In [125]: plab.plot(t, y, 'o')

Traceback (most recent call last):


File "<ipython-input-125-f9810b83ceaf>", line 1, in <module>

plab.plot(t, y, 'o')


NameError: name 'plab' is not defined



In [126]: pylab.plot(t, y, 'o')

Out[126]: [<matplotlib.lines.Line2D at 0x125feb048>]


In [127]: pylab.plot(t, y, '--')

Out[127]: [<matplotlib.lines.Line2D at 0x1273b87f0>]


In [128]: It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.