In [2]:
import numpy as np
np.random.seed(0) ## seed 설정
In [3]:
np.random.rand(5)
Out[3]:
In [5]:
x = np.arange(5)
x
Out[5]:
In [9]:
np.random.shuffle(x) ## 데이터 순서바꾸기
x
Out[9]:
In [16]:
np.random.choice(5,4, replace=False)
Out[16]:
In [21]:
np.random.choice(5,10, p=[0.1,0,0.2,0.5,0.2])
Out[21]:
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
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]:
In [5]:
"{name} is so sexy".format(name = "jiyong")
Out[5]:
In [6]:
"{name} is so sexy. he is {age} years old".format(name = "GD", age="28")
Out[6]:
In [7]:
animals = ["cat", "dog"]
In [9]:
animals.append("people")
In [13]:
animals.pop(1)
Out[13]:
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]:
In [29]:
a_dict = {"name" : "jy", "age" : 23}
In [30]:
a_dict["name"]
Out[30]:
In [34]:
True & True # And
Out[34]:
In [38]:
True | False # Or
Out[38]: