In [3]:
from IPython.display import Image
import numpy as np
In [2]:
import numpy as np
In [3]:
np.zeros(10)
Out[3]:
In [5]:
np.arange(5, 27)
Out[5]:
In [37]:
np.arange(5, 27)[::-1]
Out[37]:
In [6]:
np.random.random((3, 3, 3))
Out[6]:
In [17]:
np.random.random((3, 3, 3))*10
Out[17]:
In [18]:
np.around(np.random.random((3, 3, 3))*10)
Out[18]:
In [14]:
np.random.randint(1, 10, size=(3, 3, 3))
Out[14]:
In [25]:
Image(url='http://www.nctm.org/uploadedImages/Publications/TCM_Blog/checkerboard.png')
Out[25]:
In [16]:
chkboard = np.zeros((8, 8), dtype=int)
print(chkboard)
In [19]:
chkboard[1::2, ::2] = 1
chkboard[::2, 1::2] = 1
chkboard
Out[19]:
In [ ]:
def rwalks(steps=1000):
position = 0
walk = [position]
max_steps = int(steps)
arr = np.random.randint(0, 2, size=max_steps)
steps = np.where(arr == 0, -1, 1)
walk = np.cumsum(steps)
return walk
In [32]:
# Random Integer
a = np.random.randint(0, 2, size=100)
a
Out[32]:
In [33]:
# Where 조건(Filter)
b = np.where(a == 0, -1, 1)
b
Out[33]:
In [34]:
# Cumulative Sum
c = np.cumsum(b)
c
Out[34]:
In [35]:
# Plotting (그래프로 표현하기) Using matplotlib.pyplot
plt.plot(c)
Out[35]:
In [40]:
np.array([1, 2, 3])
Out[40]:
In [41]:
np.arange(10)
Out[41]:
In [43]:
np.linspace(1, 10, 5)
Out[43]:
In [45]:
np.ones([3, 3])
Out[45]:
In [46]:
np.zeros([2, 3])
Out[46]:
In [48]:
np.eye(6)
Out[48]:
In [49]:
np.diag([1, 2, 3])
Out[49]:
In [54]:
np.random.random([2, 3])
Out[54]:
In [57]:
np.random.random([2, 3, 4])
Out[57]:
In [25]:
a = np.random.randint(1, 10, size=(5, 5))
a
Out[25]:
In [28]:
a[2, 4]
Out[28]:
In [29]:
a[1:3]
Out[29]:
In [93]:
a = np.arange(24)
a
Out[93]:
In [37]:
a.reshape(6, 4)
Out[37]:
In [38]:
a
Out[38]:
In [33]:
a.reshape(2, )
Out[33]:
In [34]:
a.reshape(2, -1)
Out[34]:
In [35]:
a.reshape(2, 3, 4)
Out[35]:
In [92]:
a
Out[92]:
reshape 함수는 reshaping된 값을 반환해줄 뿐이지 객체를 바꿔주지는 않습니다.
In [39]:
a.shape = (2, 3, 4)
In [40]:
a
Out[40]:
shape 속성은 객체를 바꿔줍니다.
In [94]:
a.shape = (4, 6)
a
Out[94]:
In [74]:
a
Out[74]:
In [84]:
a.transpose()
Out[84]:
In [85]:
a
Out[85]:
In [95]:
b = a.transpose()
In [96]:
b
Out[96]:
In [89]:
a = b.shape
In [92]:
a
Out[92]:
In [98]:
a
Out[98]:
In [99]:
b
Out[99]:
In [100]:
b.reshape(4, 6)
Out[100]:
In [ ]:
a.shape = a
In [46]:
a
Out[46]:
In [47]:
a.T
Out[47]:
In [49]:
a
Out[49]:
In [52]:
a.ravel()
Out[52]:
In [53]:
a
Out[53]:
In [56]:
a = np.array([20,30,40,50])
b = np.arange(4)
In [55]:
a
Out[55]:
In [57]:
b
Out[57]:
In [138]:
a - b
Out[138]:
In [140]:
b**2
Out[140]:
In [143]:
10 * a
Out[143]:
In [145]:
a < 35
Out[145]:
In [58]:
a = np.array([[1, 1], [0, 1]])
b = np.array([[2, 0], [3, 4]])
In [59]:
a
Out[59]:
In [60]:
b
Out[60]:
In [154]:
# elementwise product
a*b
Out[154]:
In [155]:
# matrix product
np.dot(a, b)
Out[155]:
In [156]:
np.matrix([[1, 1], [0, 1]]) * np.matrix([[2, 0], [3, 4]])
Out[156]:
In [159]:
b.sum()
Out[159]:
In [160]:
b.min()
Out[160]:
In [161]:
b.max()
Out[161]:
In [165]:
a = np.arange(10)
a
Out[165]:
In [166]:
np.sqrt(a)
Out[166]:
In [167]:
np.exp(a)
Out[167]:
In [270]:
from numpy import genfromtxt
import datetime
import matplotlib.pyplot as plt
%matplotlib inline
In [61]:
data = np.genfromtxt('./data/2015_weather.csv', delimiter=',', dtype='object', names=True)
In [62]:
data
Out[62]:
In [65]:
data[0][0]
Out[65]:
In [406]:
data['WTHR_MAX']
Out[406]:
In [66]:
max_lst = np.where(data['LATITUDE'] == b'37.5457649', data['WTHR_MAX'], False)
max_lst
Out[66]:
In [68]:
WTHR_MAX = []
In [69]:
for i in range(len(max_lst)):
if max_lst[i] != False:
WTHR_MAX.append(max_lst[i])
In [70]:
WTHR_MAX
Out[70]:
In [399]:
plt.plot(WTHR_MAX)
Out[399]: