In [2]:
import numpy as np
np.random.seed(0) ## seed 설정

In [3]:
np.random.rand(5)


Out[3]:
array([ 0.5488135 ,  0.71518937,  0.60276338,  0.54488318,  0.4236548 ])

In [5]:
x = np.arange(5)
x


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

In [9]:
np.random.shuffle(x) ## 데이터 순서바꾸기
x


Out[9]:
array([1, 4, 2, 3, 0])

In [16]:
np.random.choice(5,4, replace=False)


Out[16]:
array([3, 2, 1, 4])

In [21]:
np.random.choice(5,10, p=[0.1,0,0.2,0.5,0.2])


Out[21]:
array([3, 4, 4, 3, 0, 3, 0, 3, 4, 3])

In [25]:
#rand 0부터 1사이의 균일분포, randn 가우시안, randint 균일분포의 난수
a = np.random.rand(10)
b = np.random.randn(10)
c = np.random.randint(10, size=10)
print a,b,c


 [ 0.98257496  0.37329075  0.42007537  0.05058812  0.36549611  0.01662797
  0.23074234  0.7649117   0.94412352  0.74999925] [ -1.38282715e-01  -2.12492027e+00  -1.03001883e+00  -5.17451865e-01
  -1.41800012e-01  -1.27648021e+00   1.48151328e+00   1.65927664e+00
   1.39611962e-04   1.50583836e+00] [8 4 4 0 9 3 7 3 2 1]

In [27]:
from sklearn.datasets import load_boston
import pandas as pd
boston = load_boston()
dfx = pd.DataFrame(boston.data, columns = boston.feature_names)
dfy = pd.DataFrame(boston.target, columns = ['MEDV'])

In [29]:
df = pd.concat([dfx,dfy], axis = 1)
df.tail()


Out[29]:
CRIM ZN INDUS CHAS NOX RM AGE DIS RAD TAX PTRATIO B LSTAT MEDV
501 0.06263 0.0 11.93 0.0 0.573 6.593 69.1 2.4786 1.0 273.0 21.0 391.99 9.67 22.4
502 0.04527 0.0 11.93 0.0 0.573 6.120 76.7 2.2875 1.0 273.0 21.0 396.90 9.08 20.6
503 0.06076 0.0 11.93 0.0 0.573 6.976 91.0 2.1675 1.0 273.0 21.0 396.90 5.64 23.9
504 0.10959 0.0 11.93 0.0 0.573 6.794 89.3 2.3889 1.0 273.0 21.0 393.45 6.48 22.0
505 0.04741 0.0 11.93 0.0 0.573 6.030 80.8 2.5050 1.0 273.0 21.0 396.90 7.88 11.9

In [5]:
"{name} is so sexy".format(name = "jiyong")


Out[5]:
'jiyong is so sexy'

In [6]:
"{name} is so sexy. he is {age} years old".format(name = "GD", age="28")


Out[6]:
'GD is so sexy. he is 28 years old'

In [7]:
animals = ["cat", "dog"]

In [9]:
animals.append("people")

In [13]:
animals.pop(1)


Out[13]:
'dog'

In [17]:
## tuple - element 값이 변하지 않음

In [21]:
width_and_height = (12,33)

In [ ]:
# set - 집합 , 순서가 없음 element가 uniq 해야함

In [22]:
name_set = set(["jy","jy","jp","jj"])

In [23]:
name_set


Out[23]:
{'jj', 'jp', 'jy'}

In [29]:
a_dict = {"name" : "jy", "age" : 23}

In [30]:
a_dict["name"]


Out[30]:
'jy'

In [34]:
True & True # And


Out[34]:
True

In [38]:
True | False # Or


Out[38]:
True