<jupyter_start><jupyter_text>how to import and use python library* 작업디렉토리를 정한다.* Python 파일 (.py)을 생성해서, 읽고 사용한다.* import 명령어로 존재하는 Python파일을 (.py) 라이브러리로 불러 사용한다.<jupyter_code>import os
mywd=%pwd
mych2wd=os.path.join(mywd,'Ch02')
%cd {mywd}
%%writefile myknn.py
from numpy import *
import operator

def createDataSet():
    group = array([[1.0,1.1],[1.0,1.0],[0,0],[0,0.1]]) # trainingSet
    labels = ['A','A','B','B'] # labels
    return group, labels
!dir myknn.py
import myknn
g,l=knn.createDataSet()
print g[:2],l[:5]
%cd {mych2wd}
import kNN
from numpy import *
dataSet = array([[1.0,1.1],[1.0,1.0],[0,0],[0,0.1]])
group = ['A','A','B','B']
inX = [0,0]
k = 3
print dataSet.shape[0]
myMat, myVec=kNN.file2matrix('datingTestSet.txt')
print myMat[:5], myVec[:5]<jupyter_output>[[  4.09200000e+04   8.32697600e+00   9.53952000e-01]
 [  1.44880000e+04   7.15346900e+00   1.67390400e+00]
 [  2.60520000e+04   1.44187100e+00   8.05124000e-01]
 [  7.51360000e+04   1.31473940e+01   4.28964000e-01]
 [  3.83440000e+04   1.66978800e+00   1.34296000e-01]] [3, 2, 1, 1, 1]
{'fraction_non_alphanumeric': 0.19793621013133209, 'fraction_numerical': 0.19606003752345216, 'mean_word_length': 4.528497409326425, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '397626', 'license': 'Apache-2.0', 'n_tokens_mistral': 638, 'n_tokens_neox': 567, 'n_words': 95, 'path': 'how_to_import.ipynb', 'repo_name': 'smu4/4s', 'size': '1066'}