l = []
l = [1,2,"Great"]
print l[0], l[-1]
print l[1:3], l[:]
print
L = range(10)
print L[::2]
print
print l * 2
print l + [3, 4, 5]
print len(l)
print
print 4 in L
1 Great [2, 'Great'] [1, 2, 'Great'] [0, 2, 4, 6, 8] [1, 2, 'Great', 1, 2, 'Great'] [1, 2, 'Great', 3, 4, 5] 3 True
a = ['spam', 'eggs', 100, 1234]
a[2] = a[2] + 23
print a
['spam', 'eggs', 123, 1234]
a = ['spam', 'eggs', 123, 1234]
a[0:2] = [1,12] # 동일한 크기에 대한 슬라이스 치환
print a
a[0:2] = [1] # 서로 다른 크기에 대한 슬라이스 치환
print a
a[0:1] = [1, 2, 3] # 서로 다른 크기에 대한 슬라이스 치환
print a
[1, 12, 123, 1234] [1, 123, 1234] [1, 2, 3, 123, 1234]
a = [1, 12, 123, 1234]
a[0:2] = []
print a
[123, 1234]
a = [123, 1234]
a[1:1] = ['spam', 'ham'] # 1번째 인덱스에 삽입
print a
b = [123, 1234]
b[1:2] = ['spam', 'ham'] # 1번째 원소에 대한 치환
print b
a[:0] = a # 리스트 맨 앞에 자기 자신을 삽입
print a
[123, 'spam', 'ham', 1234] [123, 'spam', 'ham'] [123, 'spam', 'ham', 1234, 123, 'spam', 'ham', 1234]
a = range(4)
print a
print a[::2]
a[::2] = range(0, -2, -1) # a[0::2] = [0, 2], range(0, -2 -1) = [0, -1]
print a
a[::2] = range(3) # range(3) = [0, 1, 2], 확장 슬라이스 사용하여 치환시에는 크기가 다를 때 에러 발생
[0, 1, 2, 3] [0, 2] [0, 1, -1, 3]
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-4-9e2265f969e9> in <module>() 7 print a 8 ----> 9 a[::2] = range(3) # range(3) = [0, 1, 2], 확장 슬라이스 사용하여 치환시에는 크기가 다를 때 에러 발생 ValueError: attempt to assign sequence of size 3 to extended slice of size 2
a = [1, 2, 3, 4]
del a[0]
print a
del a[1:]
print a
[2, 3, 4] [2]
a = range(4)
print a
print a[::2]
del a[::2]
print a
[0, 1, 2, 3] [0, 2] [1, 3]
a = range(5)
del a # 리스트 자체에 대한 삭제 (정확히는 리스트를 가리키는 레퍼런스를 지닌 변수 a 삭제)
print a
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-14-02d3151b8089> in <module>() 1 a = range(5) 2 del a # 리스트 자체에 대한 삭제 (정확히는 리스트를 가리키는 레퍼런스를 지닌 변수 a 삭제) ----> 3 print a NameError: name 'a' is not defined
s = [1, 2, 3]
t = ['begin', s, 'end']
print t
print t[1][1]
['begin', [1, 2, 3], 'end'] 2
s[1] = 100
print t
['begin', [1, 100, 3], 'end']
L = [1, ['a', ['x', 'y'], 'b'], 3]
print L[0]
print L[1]
print L[1][1]
print L[1][1][1]
1 ['a', ['x', 'y'], 'b'] ['x', 'y'] y
s = [1, 2, 3]
s.append(5) # 리스트 맨 마지막에 정수 값 5 추가
print s
s.insert(3, 4) # 3 인덱스 위치에 정수 값 4 추가
print s
[1, 2, 3, 5] [1, 2, 3, 4, 5]
s = [1, 2, 3, 4, 5]
print s.index(3) # 값 3의 인덱스 반환
print s.count(2) # 값 2의 개수 반환
s = [1, 2, 2, 2, 2, 2, 3, 4, 5]
print s.count(2)
2 1 5
s = [1, 2, -10, -7, 100]
s.reverse() # 자료의 순서를 뒤집기 (반환값 없음)
print s
s.sort() # 정렬 (반환값 없음)
print s
[100, -7, -10, 2, 1] [-10, -7, 1, 2, 100]
s = [10, 20, 30, 40, 50]
s.remove(10) # 자료 값 10 삭제
print s
s = [10, 20, 30, 20, 40, 50] # 자료 값이 여러개 존재하면 첫번째 것만 삭제
s.remove(20)
print s
s.extend([60, 70]) # 새로운 리스트([60, 70]를 기존 리스트 s 뒤에 병합
print s
s.append([60, 70]) # 주의: append로 새로운 리스트를 추가하면 하나의 자료 요소로서 추가
print s
[20, 30, 40, 50] [10, 30, 20, 40, 50] [10, 30, 20, 40, 50, 60, 70] [10, 30, 20, 40, 50, 60, 70, [60, 70]]
s = [10, 20, 30, 40, 50]
s.append(60)
print s
print s.pop()
print s
[10, 20, 30, 40, 50, 60] 60 [10, 20, 30, 40, 50]
s = [10, 20, 30, 40, 50]
print s.pop(0) #0 번째 인덱스 값을 꺼낸다.
print s
print s.pop(1) #1 번째 인덱스 값을 꺼낸다.
print s
10 [20, 30, 40, 50] 30 [20, 40, 50]
q = [10, 20, 30, 40, 50]
q.append(60)
print q.pop(0)
print q
10 [20, 30, 40, 50, 60]
lt = [('one', 1), ('two', 2), ('three', 3)]
for t in lt:
print 'name =', t[0] ,', num =', t[1]
name = one , num = 1 name = two , num = 2 name = three , num = 3
lt = [('one', 1), ('two', 2), ('three', 3)]
for t in lt:
print 'name = %s, num = %s' % t
name = one, num = 1 name = two, num = 2 name = three, num = 3
lt = [('one', 1), ('two', 2), ('three', 3)]
for name, num in lt:
print name, num
one 1 two 2 three 3
LL = [['one', 1], ['two', 2], ['three', 3]]
for name, num in LL:
print name, num
one 1 two 2 three 3
L = [1, 5, 3, 9, 8, 4, 2]
L.sort()
L
[1, 2, 3, 4, 5, 8, 9]
print cmp(1,2)
print cmp(5,2)
print cmp('abc', 'abc')
-1 1 0
def mycmp(a1, a2): # 대소관계에 따른 순서를 반대로 바꾸었음
return cmp(a2, a1)
L = [1, 5, 3, 2, 4, 6]
L.sort(mycmp) # 역순으로 정렬
print L
[6, 5, 4, 3, 2, 1]
def cmp_1(a1, a2):
return cmp(a1[1], a2[1])
def cmp_2(a1, a2):
return cmp(a1[2], a2[2])
L = [ ('lee', 5, 38), ('kim', 3, 28), ('jung', 10, 36)]
L.sort()
print 'sorted by name:', L
L.sort(cmp_1)
print 'sorted by experience:', L
L.sort(cmp_2)
print 'sorted by age:', L
sorted by name: [('jung', 10, 36), ('kim', 3, 28), ('lee', 5, 38)] sorted by experience: [('kim', 3, 28), ('lee', 5, 38), ('jung', 10, 36)] sorted by age: [('kim', 3, 28), ('jung', 10, 36), ('lee', 5, 38)]
L = [1, 6, 3, 8, 6, 2, 9]
L.sort(reverse = True)
L
[9, 8, 6, 6, 3, 2, 1]
L = ['123', '34', '56', '2345']
L.sort()
print L
L.sort(key=int)
print L
['123', '2345', '34', '56'] ['34', '56', '123', '2345']
L = [1, 6, 3, 8, 6, 2, 9]
newList = L.sort()
print newList
print L
None [1, 2, 3, 6, 6, 8, 9]
L = [1, 6, 3, 8, 6, 2, 9]
newList = sorted(L)
print newList
print L
[1, 2, 3, 6, 6, 8, 9] [1, 6, 3, 8, 6, 2, 9]
for ele in sorted(L):
print ele,
1 2 3 6 6 8 9
def mycmp(a1, a2): # 대소관계에 따른 순서를 반대로 바꾸었음
return cmp(a2, a1)
L = [1, 5, 3, 2, 4, 6]
print sorted(L, mycmp) # 역순으로 정렬
print L
[6, 5, 4, 3, 2, 1] [1, 5, 3, 2, 4, 6]
L = [1, 6, 3, 8, 6, 2, 9]
print sorted(L, reverse=True)
L = ['123', '34', '56', '2345']
print sorted(L, key=int)
[9, 8, 6, 6, 3, 2, 1] ['34', '56', '123', '2345']
L = [1, 6, 3, 8, 6, 2, 9]
r = L.reverse()
print r
print L
None [9, 2, 6, 8, 3, 6, 1]
L = [1, 6, 3, 8, 6, 2, 9]
L.reverse() # 역순으로 뒤집는다.
for ele in L:
print ele + 2,
print
L.reverse() # 다시 원상태로 복귀시킨다.
print L
11 4 8 10 5 8 3 [1, 6, 3, 8, 6, 2, 9]
L = [1, 6, 3, 8, 6, 2, 9]
print L
for ele in reversed(L):
print ele + 2,
print
print L
[1, 6, 3, 8, 6, 2, 9] 11 4 8 10 5 8 3 [1, 6, 3, 8, 6, 2, 9]
L = []
for k in range(10):
L.append(k*k)
print L
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
L = [k * k for k in range(10)]
print L
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[expression for expr1 in sequence1 for expr2 in sequence2 ... for exprN in sequenceN if condition]
l = [] for expr1 in sequence1: for expr2 in sequence2: ... for exprtN in sequenceN: if condition: l.append(expression)
L = [k * k for k in range(10) if k % 2] # 홀수의 제곱만 리스트로 형성
print L
[1, 9, 25, 49, 81]
L = []
for k in range(10):
if k%2:
L.append(k*k)
print L
[1, 9, 25, 49, 81]
[(i, j, i*j) for i in range(2, 100, 2)
for j in range(3, 100, 3)
if (i + j) % 7 == 0]
[(2, 12, 24), (2, 33, 66), (2, 54, 108), (2, 75, 150), (2, 96, 192), (4, 3, 12), (4, 24, 96), (4, 45, 180), (4, 66, 264), (4, 87, 348), (6, 15, 90), (6, 36, 216), (6, 57, 342), (6, 78, 468), (6, 99, 594), (8, 6, 48), (8, 27, 216), (8, 48, 384), (8, 69, 552), (8, 90, 720), (10, 18, 180), (10, 39, 390), (10, 60, 600), (10, 81, 810), (12, 9, 108), (12, 30, 360), (12, 51, 612), (12, 72, 864), (12, 93, 1116), (14, 21, 294), (14, 42, 588), (14, 63, 882), (14, 84, 1176), (16, 12, 192), (16, 33, 528), (16, 54, 864), (16, 75, 1200), (16, 96, 1536), (18, 3, 54), (18, 24, 432), (18, 45, 810), (18, 66, 1188), (18, 87, 1566), (20, 15, 300), (20, 36, 720), (20, 57, 1140), (20, 78, 1560), (20, 99, 1980), (22, 6, 132), (22, 27, 594), (22, 48, 1056), (22, 69, 1518), (22, 90, 1980), (24, 18, 432), (24, 39, 936), (24, 60, 1440), (24, 81, 1944), (26, 9, 234), (26, 30, 780), (26, 51, 1326), (26, 72, 1872), (26, 93, 2418), (28, 21, 588), (28, 42, 1176), (28, 63, 1764), (28, 84, 2352), (30, 12, 360), (30, 33, 990), (30, 54, 1620), (30, 75, 2250), (30, 96, 2880), (32, 3, 96), (32, 24, 768), (32, 45, 1440), (32, 66, 2112), (32, 87, 2784), (34, 15, 510), (34, 36, 1224), (34, 57, 1938), (34, 78, 2652), (34, 99, 3366), (36, 6, 216), (36, 27, 972), (36, 48, 1728), (36, 69, 2484), (36, 90, 3240), (38, 18, 684), (38, 39, 1482), (38, 60, 2280), (38, 81, 3078), (40, 9, 360), (40, 30, 1200), (40, 51, 2040), (40, 72, 2880), (40, 93, 3720), (42, 21, 882), (42, 42, 1764), (42, 63, 2646), (42, 84, 3528), (44, 12, 528), (44, 33, 1452), (44, 54, 2376), (44, 75, 3300), (44, 96, 4224), (46, 3, 138), (46, 24, 1104), (46, 45, 2070), (46, 66, 3036), (46, 87, 4002), (48, 15, 720), (48, 36, 1728), (48, 57, 2736), (48, 78, 3744), (48, 99, 4752), (50, 6, 300), (50, 27, 1350), (50, 48, 2400), (50, 69, 3450), (50, 90, 4500), (52, 18, 936), (52, 39, 2028), (52, 60, 3120), (52, 81, 4212), (54, 9, 486), (54, 30, 1620), (54, 51, 2754), (54, 72, 3888), (54, 93, 5022), (56, 21, 1176), (56, 42, 2352), (56, 63, 3528), (56, 84, 4704), (58, 12, 696), (58, 33, 1914), (58, 54, 3132), (58, 75, 4350), (58, 96, 5568), (60, 3, 180), (60, 24, 1440), (60, 45, 2700), (60, 66, 3960), (60, 87, 5220), (62, 15, 930), (62, 36, 2232), (62, 57, 3534), (62, 78, 4836), (62, 99, 6138), (64, 6, 384), (64, 27, 1728), (64, 48, 3072), (64, 69, 4416), (64, 90, 5760), (66, 18, 1188), (66, 39, 2574), (66, 60, 3960), (66, 81, 5346), (68, 9, 612), (68, 30, 2040), (68, 51, 3468), (68, 72, 4896), (68, 93, 6324), (70, 21, 1470), (70, 42, 2940), (70, 63, 4410), (70, 84, 5880), (72, 12, 864), (72, 33, 2376), (72, 54, 3888), (72, 75, 5400), (72, 96, 6912), (74, 3, 222), (74, 24, 1776), (74, 45, 3330), (74, 66, 4884), (74, 87, 6438), (76, 15, 1140), (76, 36, 2736), (76, 57, 4332), (76, 78, 5928), (76, 99, 7524), (78, 6, 468), (78, 27, 2106), (78, 48, 3744), (78, 69, 5382), (78, 90, 7020), (80, 18, 1440), (80, 39, 3120), (80, 60, 4800), (80, 81, 6480), (82, 9, 738), (82, 30, 2460), (82, 51, 4182), (82, 72, 5904), (82, 93, 7626), (84, 21, 1764), (84, 42, 3528), (84, 63, 5292), (84, 84, 7056), (86, 12, 1032), (86, 33, 2838), (86, 54, 4644), (86, 75, 6450), (86, 96, 8256), (88, 3, 264), (88, 24, 2112), (88, 45, 3960), (88, 66, 5808), (88, 87, 7656), (90, 15, 1350), (90, 36, 3240), (90, 57, 5130), (90, 78, 7020), (90, 99, 8910), (92, 6, 552), (92, 27, 2484), (92, 48, 4416), (92, 69, 6348), (92, 90, 8280), (94, 18, 1692), (94, 39, 3666), (94, 60, 5640), (94, 81, 7614), (96, 9, 864), (96, 30, 2880), (96, 51, 4896), (96, 72, 6912), (96, 93, 8928), (98, 21, 2058), (98, 42, 4116), (98, 63, 6174), (98, 84, 8232)]
seq1 = 'abc'
seq2 = (1, 2, 3)
[ (x, y) for x in seq1 for y in seq2]
[('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('b', 3), ('c', 1), ('c', 2), ('c', 3)]
다음은 고등학교 수학에서 배운 집합의 표기 방법이다.
파이썬의 리스트 내포(list comprehension)는 바로 위 집합 표기법과 유사한 방식의 리터럴이다.
위 집합들을 리스트 내포 방식으로 표현하면 다음과 같다.
words = 'The quick brown fox jumps over the lazy and fast dog'.split()
stuff = [w for w in words if w.startswith('f')]
print stuff
['fox', 'fast']
[(x,y,z) for x in range(1,30) for y in range(x,30) for z in range(y,30) if x**2 + y**2 == z**2]
[(3, 4, 5), (5, 12, 13), (6, 8, 10), (7, 24, 25), (8, 15, 17), (9, 12, 15), (10, 24, 26), (12, 16, 20), (15, 20, 25), (20, 21, 29)]
words = 'The quick brown fox jumps over the lazy dog'.split()
stuff = [[w.upper(), w.lower(), len(w)] for w in words]
for i in stuff:
print i
['THE', 'the', 3] ['QUICK', 'quick', 5] ['BROWN', 'brown', 5] ['FOX', 'fox', 3] ['JUMPS', 'jumps', 5] ['OVER', 'over', 4] ['THE', 'the', 3] ['LAZY', 'lazy', 4] ['DOG', 'dog', 3]
list_a = ['A', 'B']
list_b = ['C', 'D']
print [x+y for x in list_a for y in list_b]
print
print [[x+y for x in list_a] for y in list_b]
['AC', 'AD', 'BC', 'BD'] [['AC', 'BC'], ['AD', 'BD']]
l = []
for y in list_b:
l2 = []
for x in list_a:
l2.append(x+y)
l.append(l2)
print l
[['AC', 'BC'], ['AD', 'BD']]
CL = ['is fun']
CL.insert(0, CL)
print CL
print CL[0]
print CL[0][0]
print CL[0][0][0]
[[...], 'is fun'] [[...], 'is fun'] [[...], 'is fun'] [[...], 'is fun']
print range(10) # 0(Included)부터 10(Excluded)까지
print range(5, 15) # 5(Included)부터 15(Excluded)까지
print range(5, 15, 2) # 0(Included)부터 10(Excluded)까지, Step: 2
print range(0, -10, -1) # 0(Included)부터 -10(Excluded)까지, Step: -1
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [5, 6, 7, 8, 9, 10, 11, 12, 13, 14] [5, 7, 9, 11, 13] [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
for el in range(10):
print el, 'inch=', el * 2.54, 'centi'
0 inch= 0.0 centi 1 inch= 2.54 centi 2 inch= 5.08 centi 3 inch= 7.62 centi 4 inch= 10.16 centi 5 inch= 12.7 centi 6 inch= 15.24 centi 7 inch= 17.78 centi 8 inch= 20.32 centi 9 inch= 22.86 centi
sun, mon, tue, wed, thu, fri, sat = range(7)
print sun, mon, tue, wed, thu, fri, sat
0 1 2 3 4 5 6
print dir()
['ALLOW_THREADS', 'Annotation', 'Arrow', 'Artist', 'AutoLocator', 'Axes', 'BUFSIZE', 'Button', 'CLIP', 'Circle', 'ComplexWarning', 'DAILY', 'DataSource', 'DateFormatter', 'DateLocator', 'DayLocator', 'ERR_CALL', 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'FR', 'False_', 'Figure', 'FigureCanvasBase', 'FixedFormatter', 'FixedLocator', 'FormatStrFormatter', 'Formatter', 'FuncFormatter', 'GridSpec', 'HOURLY', 'HourLocator', 'In', 'IndexDateFormatter', 'IndexLocator', 'Inf', 'Infinity', 'LinAlgError', 'Line2D', 'LinearLocator', 'Locator', 'LogFormatter', 'LogFormatterExponent', 'LogFormatterMathtext', 'LogLocator', 'MAXDIMS', 'MINUTELY', 'MO', 'MONTHLY', 'MachAr', 'MaxNLocator', 'MinuteLocator', 'ModuleDeprecationWarning', 'MonthLocator', 'MultipleLocator', 'NAN', 'NINF', 'NZERO', 'NaN', 'Normalize', 'NullFormatter', 'NullLocator', 'Out', 'PINF', 'PZERO', 'PackageLoader', 'PolarAxes', 'Polygon', 'RAISE', 'RRuleLocator', 'RankWarning', 'Rectangle', 'SA', 'SECONDLY', 'SHIFT_DIVIDEBYZERO', 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'SU', 'ScalarFormatter', 'ScalarType', 'SecondLocator', 'Slider', 'Subplot', 'SubplotTool', 'TH', 'TU', 'Tester', 'Text', 'TickHelper', 'True_', 'UFUNC_BUFSIZE_DEFAULT', 'UFUNC_PYVALS_NAME', 'WE', 'WEEKLY', 'WRAP', 'WeekdayLocator', 'Widget', 'YEARLY', 'YearLocator', '_', '__', '___', '__builtin__', '__builtins__', '__doc__', '__name__', '__version__', '_dh', '_i', '_i1', '_i2', '_i3', '_ih', '_ii', '_iii', '_oh', '_sh', 'absolute', 'absolute_import', 'acorr', 'add', 'add_docstring', 'add_newdoc', 'add_newdoc_ufunc', 'add_newdocs', 'alen', 'all', 'allclose', 'alltrue', 'alterdot', 'amap', 'amax', 'amin', 'angle', 'annotate', 'any', 'append', 'apply_along_axis', 'apply_over_axes', 'arange', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'argmax', 'argmin', 'argpartition', 'argsort', 'argwhere', 'around', 'array', 'array2string', 'array_equal', 'array_equiv', 'array_repr', 'array_split', 'array_str', 'arrow', 'asanyarray', 'asarray', 'asarray_chkfinite', 'ascontiguousarray', 'asfarray', 'asfortranarray', 'asmatrix', 'asscalar', 'atleast_1d', 'atleast_2d', 'atleast_3d', 'autoscale', 'autumn', 'average', 'axes', 'axhline', 'axhspan', 'axis', 'axvline', 'axvspan', 'bar', 'barbs', 'barh', 'bartlett', 'base_repr', 'bench', 'beta', 'binary_repr', 'bincount', 'binomial', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'bivariate_normal', 'blackman', 'bmat', 'bone', 'bool8', 'bool_', 'box', 'boxplot', 'broadcast', 'broadcast_arrays', 'broken_barh', 'busday_count', 'busday_offset', 'busdaycalendar', 'byte', 'byte_bounds', 'bytes', 'bytes_', 'c_', 'can_cast', 'cast', 'cbook', 'cdouble', 'ceil', 'center_matrix', 'cfloat', 'char', 'character', 'chararray', 'chisquare', 'cholesky', 'choose', 'cla', 'clabel', 'clf', 'clim', 'clip', 'clongdouble', 'clongfloat', 'close', 'cm', 'cohere', 'colorbar', 'colormaps', 'colors', 'column_stack', 'common_type', 'compare_chararrays', 'complex128', 'complex256', 'complex64', 'complex_', 'complexfloating', 'compress', 'concatenate', 'cond', 'conj', 'conjugate', 'connect', 'contour', 'contourf', 'convolve', 'cool', 'copper', 'copy', 'copysign', 'copyto', 'corrcoef', 'correlate', 'cos', 'cosh', 'count_nonzero', 'cov', 'cross', 'csd', 'csingle', 'csv2rec', 'ctypeslib', 'cumprod', 'cumproduct', 'cumsum', 'date2num', 'datestr2num', 'datetime', 'datetime64', 'datetime_as_string', 'datetime_data', 'dedent', 'deg2rad', 'degrees', 'delaxes', 'delete', 'demean', 'deprecate', 'deprecate_with_doc', 'det', 'detrend', 'detrend_linear', 'detrend_mean', 'detrend_none', 'diag', 'diag_indices', 'diag_indices_from', 'diagflat', 'diagonal', 'diff', 'digitize', 'disconnect', 'disp', 'display', 'dist', 'dist_point_to_segment', 'distances_along_curve', 'divide', 'division', 'docstring', 'dot', 'double', 'drange', 'draw', 'draw_if_interactive', 'dsplit', 'dstack', 'dtype', 'e', 'ediff1d', 'eig', 'eigh', 'eigvals', 'eigvalsh', 'einsum', 'emath', 'empty', 'empty_like', 'entropy', 'epoch2num', 'equal', 'errorbar', 'errstate', 'euler_gamma', 'eventplot', 'exception_to_str', 'exit', 'exp', 'exp2', 'exp_safe', 'expand_dims', 'expm1', 'exponential', 'extract', 'eye', 'f', 'fabs', 'fastCopyAndTranspose', 'fft', 'fft2', 'fftfreq', 'fftn', 'fftpack', 'fftpack_lite', 'fftshift', 'fftsurr', 'figaspect', 'figimage', 'figlegend', 'fignum_exists', 'figsize', 'figtext', 'figure', 'fill', 'fill_between', 'fill_betweenx', 'fill_diagonal', 'find', 'find_common_type', 'findobj', 'finfo', 'fix', 'flag', 'flatiter', 'flatnonzero', 'flatten', 'flexible', 'fliplr', 'flipud', 'float128', 'float16', 'float32', 'float64', 'float_', 'floating', 'floor', 'floor_divide', 'fmax', 'fmin', 'fmod', 'format_parser', 'frange', 'frexp', 'fri', 'frombuffer', 'fromfile', 'fromfunction', 'fromiter', 'frompyfunc', 'fromregex', 'fromstring', 'full', 'full_like', 'fv', 'gamma', 'gca', 'gcf', 'gci', 'generic', 'genfromtxt', 'geometric', 'get', 'get_array_wrap', 'get_backend', 'get_cmap', 'get_current_fig_manager', 'get_figlabels', 'get_fignums', 'get_include', 'get_ipython', 'get_numarray_include', 'get_plot_commands', 'get_printoptions', 'get_scale_docs', 'get_scale_names', 'get_sparse_matrix', 'get_state', 'get_xyz_where', 'getbuffer', 'getbufsize', 'geterr', 'geterrcall', 'geterrobj', 'getfigs', 'getp', 'ginput', 'gradient', 'gray', 'greater', 'greater_equal', 'grid', 'griddata', 'gumbel', 'half', 'hamming', 'hanning', 'helper', 'hexbin', 'hfft', 'hist', 'hist2d', 'histogram', 'histogram2d', 'histogramdd', 'hlines', 'hold', 'hot', 'hsplit', 'hstack', 'hsv', 'hypergeometric', 'hypot', 'i0', 'identity', 'ifft', 'ifft2', 'ifftn', 'ifftshift', 'ihfft', 'iinfo', 'imag', 'imread', 'imsave', 'imshow', 'in1d', 'index_exp', 'indices', 'inexact', 'inf', 'info', 'infty', 'inner', 'insert', 'inside_poly', 'int0', 'int16', 'int32', 'int64', 'int8', 'int_', 'int_asbuffer', 'intc', 'integer', 'interactive', 'interp', 'intersect1d', 'intp', 'inv', 'invert', 'ioff', 'ion', 'ipmt', 'irfft', 'irfft2', 'irfftn', 'irr', 'is_busday', 'is_closed_polygon', 'is_numlike', 'is_string_like', 'isclose', 'iscomplex', 'iscomplexobj', 'isfinite', 'isfortran', 'ishold', 'isinf', 'isinteractive', 'isnan', 'isneginf', 'isposinf', 'ispower2', 'isreal', 'isrealobj', 'isscalar', 'issctype', 'issubclass_', 'issubdtype', 'issubsctype', 'isvector', 'iterable', 'ix_', 'jet', 'kaiser', 'kron', 'l1norm', 'l2norm', 'lapack_lite', 'laplace', 'ldexp', 'left_shift', 'legend', 'less', 'less_equal', 'levypdf', 'lexsort', 'linalg', 'linspace', 'little_endian', 'load', 'loads', 'loadtxt', 'locator_params', 'log', 'log10', 'log1p', 'log2', 'logaddexp', 'logaddexp2', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logistic', 'loglog', 'lognormal', 'logseries', 'logspace', 'longcomplex', 'longdouble', 'longest_contiguous_ones', 'longest_ones', 'longfloat', 'longlong', 'lookfor', 'lstsq', 'ma', 'mafromtxt', 'margins', 'mask_indices', 'mat', 'math', 'matplotlib', 'matrix', 'matrix_power', 'matrix_rank', 'matshow', 'maximum', 'maximum_sctype', 'may_share_memory', 'mean', 'median', 'memmap', 'meshgrid', 'mgrid', 'min_scalar_type', 'minimum', 'minorticks_off', 'minorticks_on', 'mintypecode', 'mirr', 'mlab', 'mod', 'modf', 'mon', 'movavg', 'mpl', 'msort', 'multinomial', 'multiply', 'multivariate_normal', 'mx2num', 'nan', 'nan_to_num', 'nanargmax', 'nanargmin', 'nanmax', 'nanmean', 'nanmin', 'nanstd', 'nansum', 'nanvar', 'nbytes', 'ndarray', 'ndenumerate', 'ndfromtxt', 'ndim', 'ndindex', 'nditer', 'negative', 'negative_binomial', 'nested_iters', 'new_figure_manager', 'newaxis', 'newbuffer', 'nextafter', 'noncentral_chisquare', 'noncentral_f', 'nonzero', 'norm', 'norm_flat', 'normal', 'normalize', 'normpdf', 'not_equal', 'np', 'nper', 'npv', 'num2date', 'num2epoch', 'number', 'numpy', 'obj2sctype', 'object0', 'object_', 'ogrid', 'ones', 'ones_like', 'outer', 'over', 'packbits', 'pad', 'pareto', 'partition', 'path_length', 'pause', 'pcolor', 'pcolormesh', 'percentile', 'permutation', 'pi', 'pie', 'piecewise', 'pink', 'pinv', 'pkgload', 'place', 'plot', 'plot_date', 'plotfile', 'plotting', 'plt', 'pmt', 'poisson', 'polar', 'poly', 'poly1d', 'poly_below', 'poly_between', 'polyadd', 'polyder', 'polydiv', 'polyfit', 'polyint', 'polymul', 'polysub', 'polyval', 'power', 'ppmt', 'prctile', 'prctile_rank', 'prepca', 'print_function', 'prism', 'prod', 'product', 'promote_types', 'psd', 'ptp', 'put', 'putmask', 'pv', 'pylab', 'pylab_setup', 'pyplot', 'qr', 'quit', 'quiver', 'quiverkey', 'r_', 'rad2deg', 'radians', 'rand', 'randint', 'randn', 'random', 'random_integers', 'random_sample', 'ranf', 'rank', 'rate', 'ravel', 'ravel_multi_index', 'rayleigh', 'rc', 'rcParams', 'rcParamsDefault', 'rc_context', 'rcdefaults', 'real', 'real_if_close', 'rec', 'rec2csv', 'rec_append_fields', 'rec_drop_fields', 'rec_join', 'recarray', 'recfromcsv', 'recfromtxt', 'reciprocal', 'record', 'register_cmap', 'relativedelta', 'remainder', 'repeat', 'require', 'reshape', 'resize', 'restoredot', 'result_type', 'rfft', 'rfft2', 'rfftfreq', 'rfftn', 'rgrids', 'right_shift', 'rint', 'rk4', 'rms_flat', 'roll', 'rollaxis', 'roots', 'rot90', 'round_', 'row_stack', 'rrule', 's_', 'safe_eval', 'sample', 'sat', 'save', 'savefig', 'savetxt', 'savez', 'savez_compressed', 'sca', 'scatter', 'sci', 'sctype2char', 'sctypeDict', 'sctypeNA', 'sctypes', 'searchsorted', 'seed', 'segments_intersect', 'select', 'semilogx', 'semilogy', 'set_cmap', 'set_numeric_ops', 'set_printoptions', 'set_state', 'set_string_function', 'setbufsize', 'setdiff1d', 'seterr', 'seterrcall', 'seterrobj', 'setp', 'setxor1d', 'shape', 'short', 'show', 'show_config', 'shuffle', 'sign', 'signbit', 'signedinteger', 'silent_list', 'sin', 'sinc', 'single', 'singlecomplex', 'sinh', 'size', 'slogdet', 'slopes', 'solve', 'sometrue', 'sort', 'sort_complex', 'source', 'spacing', 'specgram', 'spectral', 'split', 'spring', 'spy', 'sqrt', 'square', 'squeeze', 'stackplot', 'standard_cauchy', 'standard_exponential', 'standard_gamma', 'standard_normal', 'standard_t', 'std', 'stem', 'step', 'stineman_interp', 'str_', 'streamplot', 'string0', 'string_', 'strpdate2num', 'subplot', 'subplot2grid', 'subplot_tool', 'subplots', 'subplots_adjust', 'subtract', 'sum', 'summer', 'sun', 'suptitle', 'svd', 'swapaxes', 'switch_backend', 'sys', 'table', 'take', 'tan', 'tanh', 'tensordot', 'tensorinv', 'tensorsolve', 'test', 'text', 'thetagrids', 'thu', 'tick_params', 'ticklabel_format', 'tight_layout', 'tile', 'timedelta64', 'title', 'trace', 'transpose', 'trapz', 'tri', 'triangular', 'tricontour', 'tricontourf', 'tril', 'tril_indices', 'tril_indices_from', 'trim_zeros', 'tripcolor', 'triplot', 'triu', 'triu_indices', 'triu_indices_from', 'true_divide', 'trunc', 'tue', 'twinx', 'twiny', 'typeDict', 'typeNA', 'typecodes', 'typename', 'ubyte', 'ufunc', 'uint', 'uint0', 'uint16', 'uint32', 'uint64', 'uint8', 'uintc', 'uintp', 'ulonglong', 'unicode0', 'unicode_', 'uniform', 'union1d', 'unique', 'unpackbits', 'unravel_index', 'unsignedinteger', 'unwrap', 'use_fastnumpy', 'ushort', 'vander', 'var', 'vdot', 'vector_lengths', 'vectorize', 'vlines', 'void', 'void0', 'vonmises', 'vsplit', 'vstack', 'waitforbuttonpress', 'wald', 'warnings', 'wed', 'weibull', 'where', 'who', 'window_hanning', 'window_none', 'winter', 'xcorr', 'xkcd', 'xlabel', 'xlim', 'xscale', 'xticks', 'ylabel', 'ylim', 'yscale', 'yticks', 'zeros', 'zeros_like', 'zipf']
a = 100
print dir()
['ALLOW_THREADS', 'Annotation', 'Arrow', 'Artist', 'AutoLocator', 'Axes', 'BUFSIZE', 'Button', 'CLIP', 'Circle', 'ComplexWarning', 'DAILY', 'DataSource', 'DateFormatter', 'DateLocator', 'DayLocator', 'ERR_CALL', 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'FR', 'False_', 'Figure', 'FigureCanvasBase', 'FixedFormatter', 'FixedLocator', 'FormatStrFormatter', 'Formatter', 'FuncFormatter', 'GridSpec', 'HOURLY', 'HourLocator', 'In', 'IndexDateFormatter', 'IndexLocator', 'Inf', 'Infinity', 'LinAlgError', 'Line2D', 'LinearLocator', 'Locator', 'LogFormatter', 'LogFormatterExponent', 'LogFormatterMathtext', 'LogLocator', 'MAXDIMS', 'MINUTELY', 'MO', 'MONTHLY', 'MachAr', 'MaxNLocator', 'MinuteLocator', 'ModuleDeprecationWarning', 'MonthLocator', 'MultipleLocator', 'NAN', 'NINF', 'NZERO', 'NaN', 'Normalize', 'NullFormatter', 'NullLocator', 'Out', 'PINF', 'PZERO', 'PackageLoader', 'PolarAxes', 'Polygon', 'RAISE', 'RRuleLocator', 'RankWarning', 'Rectangle', 'SA', 'SECONDLY', 'SHIFT_DIVIDEBYZERO', 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'SU', 'ScalarFormatter', 'ScalarType', 'SecondLocator', 'Slider', 'Subplot', 'SubplotTool', 'TH', 'TU', 'Tester', 'Text', 'TickHelper', 'True_', 'UFUNC_BUFSIZE_DEFAULT', 'UFUNC_PYVALS_NAME', 'WE', 'WEEKLY', 'WRAP', 'WeekdayLocator', 'Widget', 'YEARLY', 'YearLocator', '_', '__', '___', '__builtin__', '__builtins__', '__doc__', '__name__', '__version__', '_dh', '_i', '_i1', '_i2', '_i3', '_i4', '_i5', '_ih', '_ii', '_iii', '_oh', '_sh', 'a', 'absolute', 'absolute_import', 'acorr', 'add', 'add_docstring', 'add_newdoc', 'add_newdoc_ufunc', 'add_newdocs', 'alen', 'all', 'allclose', 'alltrue', 'alterdot', 'amap', 'amax', 'amin', 'angle', 'annotate', 'any', 'append', 'apply_along_axis', 'apply_over_axes', 'arange', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'argmax', 'argmin', 'argpartition', 'argsort', 'argwhere', 'around', 'array', 'array2string', 'array_equal', 'array_equiv', 'array_repr', 'array_split', 'array_str', 'arrow', 'asanyarray', 'asarray', 'asarray_chkfinite', 'ascontiguousarray', 'asfarray', 'asfortranarray', 'asmatrix', 'asscalar', 'atleast_1d', 'atleast_2d', 'atleast_3d', 'autoscale', 'autumn', 'average', 'axes', 'axhline', 'axhspan', 'axis', 'axvline', 'axvspan', 'bar', 'barbs', 'barh', 'bartlett', 'base_repr', 'bench', 'beta', 'binary_repr', 'bincount', 'binomial', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'bivariate_normal', 'blackman', 'bmat', 'bone', 'bool8', 'bool_', 'box', 'boxplot', 'broadcast', 'broadcast_arrays', 'broken_barh', 'busday_count', 'busday_offset', 'busdaycalendar', 'byte', 'byte_bounds', 'bytes', 'bytes_', 'c_', 'can_cast', 'cast', 'cbook', 'cdouble', 'ceil', 'center_matrix', 'cfloat', 'char', 'character', 'chararray', 'chisquare', 'cholesky', 'choose', 'cla', 'clabel', 'clf', 'clim', 'clip', 'clongdouble', 'clongfloat', 'close', 'cm', 'cohere', 'colorbar', 'colormaps', 'colors', 'column_stack', 'common_type', 'compare_chararrays', 'complex128', 'complex256', 'complex64', 'complex_', 'complexfloating', 'compress', 'concatenate', 'cond', 'conj', 'conjugate', 'connect', 'contour', 'contourf', 'convolve', 'cool', 'copper', 'copy', 'copysign', 'copyto', 'corrcoef', 'correlate', 'cos', 'cosh', 'count_nonzero', 'cov', 'cross', 'csd', 'csingle', 'csv2rec', 'ctypeslib', 'cumprod', 'cumproduct', 'cumsum', 'date2num', 'datestr2num', 'datetime', 'datetime64', 'datetime_as_string', 'datetime_data', 'dedent', 'deg2rad', 'degrees', 'delaxes', 'delete', 'demean', 'deprecate', 'deprecate_with_doc', 'det', 'detrend', 'detrend_linear', 'detrend_mean', 'detrend_none', 'diag', 'diag_indices', 'diag_indices_from', 'diagflat', 'diagonal', 'diff', 'digitize', 'disconnect', 'disp', 'display', 'dist', 'dist_point_to_segment', 'distances_along_curve', 'divide', 'division', 'docstring', 'dot', 'double', 'drange', 'draw', 'draw_if_interactive', 'dsplit', 'dstack', 'dtype', 'e', 'ediff1d', 'eig', 'eigh', 'eigvals', 'eigvalsh', 'einsum', 'emath', 'empty', 'empty_like', 'entropy', 'epoch2num', 'equal', 'errorbar', 'errstate', 'euler_gamma', 'eventplot', 'exception_to_str', 'exit', 'exp', 'exp2', 'exp_safe', 'expand_dims', 'expm1', 'exponential', 'extract', 'eye', 'f', 'fabs', 'fastCopyAndTranspose', 'fft', 'fft2', 'fftfreq', 'fftn', 'fftpack', 'fftpack_lite', 'fftshift', 'fftsurr', 'figaspect', 'figimage', 'figlegend', 'fignum_exists', 'figsize', 'figtext', 'figure', 'fill', 'fill_between', 'fill_betweenx', 'fill_diagonal', 'find', 'find_common_type', 'findobj', 'finfo', 'fix', 'flag', 'flatiter', 'flatnonzero', 'flatten', 'flexible', 'fliplr', 'flipud', 'float128', 'float16', 'float32', 'float64', 'float_', 'floating', 'floor', 'floor_divide', 'fmax', 'fmin', 'fmod', 'format_parser', 'frange', 'frexp', 'fri', 'frombuffer', 'fromfile', 'fromfunction', 'fromiter', 'frompyfunc', 'fromregex', 'fromstring', 'full', 'full_like', 'fv', 'gamma', 'gca', 'gcf', 'gci', 'generic', 'genfromtxt', 'geometric', 'get', 'get_array_wrap', 'get_backend', 'get_cmap', 'get_current_fig_manager', 'get_figlabels', 'get_fignums', 'get_include', 'get_ipython', 'get_numarray_include', 'get_plot_commands', 'get_printoptions', 'get_scale_docs', 'get_scale_names', 'get_sparse_matrix', 'get_state', 'get_xyz_where', 'getbuffer', 'getbufsize', 'geterr', 'geterrcall', 'geterrobj', 'getfigs', 'getp', 'ginput', 'gradient', 'gray', 'greater', 'greater_equal', 'grid', 'griddata', 'gumbel', 'half', 'hamming', 'hanning', 'helper', 'hexbin', 'hfft', 'hist', 'hist2d', 'histogram', 'histogram2d', 'histogramdd', 'hlines', 'hold', 'hot', 'hsplit', 'hstack', 'hsv', 'hypergeometric', 'hypot', 'i0', 'identity', 'ifft', 'ifft2', 'ifftn', 'ifftshift', 'ihfft', 'iinfo', 'imag', 'imread', 'imsave', 'imshow', 'in1d', 'index_exp', 'indices', 'inexact', 'inf', 'info', 'infty', 'inner', 'insert', 'inside_poly', 'int0', 'int16', 'int32', 'int64', 'int8', 'int_', 'int_asbuffer', 'intc', 'integer', 'interactive', 'interp', 'intersect1d', 'intp', 'inv', 'invert', 'ioff', 'ion', 'ipmt', 'irfft', 'irfft2', 'irfftn', 'irr', 'is_busday', 'is_closed_polygon', 'is_numlike', 'is_string_like', 'isclose', 'iscomplex', 'iscomplexobj', 'isfinite', 'isfortran', 'ishold', 'isinf', 'isinteractive', 'isnan', 'isneginf', 'isposinf', 'ispower2', 'isreal', 'isrealobj', 'isscalar', 'issctype', 'issubclass_', 'issubdtype', 'issubsctype', 'isvector', 'iterable', 'ix_', 'jet', 'kaiser', 'kron', 'l1norm', 'l2norm', 'lapack_lite', 'laplace', 'ldexp', 'left_shift', 'legend', 'less', 'less_equal', 'levypdf', 'lexsort', 'linalg', 'linspace', 'little_endian', 'load', 'loads', 'loadtxt', 'locator_params', 'log', 'log10', 'log1p', 'log2', 'logaddexp', 'logaddexp2', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logistic', 'loglog', 'lognormal', 'logseries', 'logspace', 'longcomplex', 'longdouble', 'longest_contiguous_ones', 'longest_ones', 'longfloat', 'longlong', 'lookfor', 'lstsq', 'ma', 'mafromtxt', 'margins', 'mask_indices', 'mat', 'math', 'matplotlib', 'matrix', 'matrix_power', 'matrix_rank', 'matshow', 'maximum', 'maximum_sctype', 'may_share_memory', 'mean', 'median', 'memmap', 'meshgrid', 'mgrid', 'min_scalar_type', 'minimum', 'minorticks_off', 'minorticks_on', 'mintypecode', 'mirr', 'mlab', 'mod', 'modf', 'mon', 'movavg', 'mpl', 'msort', 'multinomial', 'multiply', 'multivariate_normal', 'mx2num', 'nan', 'nan_to_num', 'nanargmax', 'nanargmin', 'nanmax', 'nanmean', 'nanmin', 'nanstd', 'nansum', 'nanvar', 'nbytes', 'ndarray', 'ndenumerate', 'ndfromtxt', 'ndim', 'ndindex', 'nditer', 'negative', 'negative_binomial', 'nested_iters', 'new_figure_manager', 'newaxis', 'newbuffer', 'nextafter', 'noncentral_chisquare', 'noncentral_f', 'nonzero', 'norm', 'norm_flat', 'normal', 'normalize', 'normpdf', 'not_equal', 'np', 'nper', 'npv', 'num2date', 'num2epoch', 'number', 'numpy', 'obj2sctype', 'object0', 'object_', 'ogrid', 'ones', 'ones_like', 'outer', 'over', 'packbits', 'pad', 'pareto', 'partition', 'path_length', 'pause', 'pcolor', 'pcolormesh', 'percentile', 'permutation', 'pi', 'pie', 'piecewise', 'pink', 'pinv', 'pkgload', 'place', 'plot', 'plot_date', 'plotfile', 'plotting', 'plt', 'pmt', 'poisson', 'polar', 'poly', 'poly1d', 'poly_below', 'poly_between', 'polyadd', 'polyder', 'polydiv', 'polyfit', 'polyint', 'polymul', 'polysub', 'polyval', 'power', 'ppmt', 'prctile', 'prctile_rank', 'prepca', 'print_function', 'prism', 'prod', 'product', 'promote_types', 'psd', 'ptp', 'put', 'putmask', 'pv', 'pylab', 'pylab_setup', 'pyplot', 'qr', 'quit', 'quiver', 'quiverkey', 'r_', 'rad2deg', 'radians', 'rand', 'randint', 'randn', 'random', 'random_integers', 'random_sample', 'ranf', 'rank', 'rate', 'ravel', 'ravel_multi_index', 'rayleigh', 'rc', 'rcParams', 'rcParamsDefault', 'rc_context', 'rcdefaults', 'real', 'real_if_close', 'rec', 'rec2csv', 'rec_append_fields', 'rec_drop_fields', 'rec_join', 'recarray', 'recfromcsv', 'recfromtxt', 'reciprocal', 'record', 'register_cmap', 'relativedelta', 'remainder', 'repeat', 'require', 'reshape', 'resize', 'restoredot', 'result_type', 'rfft', 'rfft2', 'rfftfreq', 'rfftn', 'rgrids', 'right_shift', 'rint', 'rk4', 'rms_flat', 'roll', 'rollaxis', 'roots', 'rot90', 'round_', 'row_stack', 'rrule', 's_', 'safe_eval', 'sample', 'sat', 'save', 'savefig', 'savetxt', 'savez', 'savez_compressed', 'sca', 'scatter', 'sci', 'sctype2char', 'sctypeDict', 'sctypeNA', 'sctypes', 'searchsorted', 'seed', 'segments_intersect', 'select', 'semilogx', 'semilogy', 'set_cmap', 'set_numeric_ops', 'set_printoptions', 'set_state', 'set_string_function', 'setbufsize', 'setdiff1d', 'seterr', 'seterrcall', 'seterrobj', 'setp', 'setxor1d', 'shape', 'short', 'show', 'show_config', 'shuffle', 'sign', 'signbit', 'signedinteger', 'silent_list', 'sin', 'sinc', 'single', 'singlecomplex', 'sinh', 'size', 'slogdet', 'slopes', 'solve', 'sometrue', 'sort', 'sort_complex', 'source', 'spacing', 'specgram', 'spectral', 'split', 'spring', 'spy', 'sqrt', 'square', 'squeeze', 'stackplot', 'standard_cauchy', 'standard_exponential', 'standard_gamma', 'standard_normal', 'standard_t', 'std', 'stem', 'step', 'stineman_interp', 'str_', 'streamplot', 'string0', 'string_', 'strpdate2num', 'subplot', 'subplot2grid', 'subplot_tool', 'subplots', 'subplots_adjust', 'subtract', 'sum', 'summer', 'sun', 'suptitle', 'svd', 'swapaxes', 'switch_backend', 'sys', 'table', 'take', 'tan', 'tanh', 'tensordot', 'tensorinv', 'tensorsolve', 'test', 'text', 'thetagrids', 'thu', 'tick_params', 'ticklabel_format', 'tight_layout', 'tile', 'timedelta64', 'title', 'trace', 'transpose', 'trapz', 'tri', 'triangular', 'tricontour', 'tricontourf', 'tril', 'tril_indices', 'tril_indices_from', 'trim_zeros', 'tripcolor', 'triplot', 'triu', 'triu_indices', 'triu_indices_from', 'true_divide', 'trunc', 'tue', 'twinx', 'twiny', 'typeDict', 'typeNA', 'typecodes', 'typename', 'ubyte', 'ufunc', 'uint', 'uint0', 'uint16', 'uint32', 'uint64', 'uint8', 'uintc', 'uintp', 'ulonglong', 'unicode0', 'unicode_', 'uniform', 'union1d', 'unique', 'unpackbits', 'unravel_index', 'unsignedinteger', 'unwrap', 'use_fastnumpy', 'ushort', 'vander', 'var', 'vdot', 'vector_lengths', 'vectorize', 'vlines', 'void', 'void0', 'vonmises', 'vsplit', 'vstack', 'waitforbuttonpress', 'wald', 'warnings', 'wed', 'weibull', 'where', 'who', 'window_hanning', 'window_none', 'winter', 'xcorr', 'xkcd', 'xlabel', 'xlim', 'xscale', 'xticks', 'ylabel', 'ylim', 'yscale', 'yticks', 'zeros', 'zeros_like', 'zipf']
print "name: " # 로컬 이름
print __name__
print
print "doc: " # 로컬에 지정된 문서문자열
print __doc__
print
name: __main__ doc: Automatically created module for IPython interactive environment
import math
print "math.__name__: ", math.__name__
print
print dir(math) # dir() 내장 함수에 모듈을 인자로 전달하면 해당 모듈이 지원하는 멤버 변수 및 함수 목록을 얻는다.
print
print "math.__doc__:", math.__doc__
print
print "math.log10.__doc__: ", math.log10.__doc__
math.__name__: math ['__doc__', '__file__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc'] math.__doc__: This module is always available. It provides access to the mathematical functions defined by the C standard. math.log10.__doc__: log10(x) Return the base 10 logarithm of x.
import sys
print dir(sys) # dir() 내장 함수에 모듈을 인자로 전달하면 해당 모듈이 지원하는 멤버 변수 및 함수 목록을 얻는다.
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_executable', '_getframe', '_home', '_mercurial', 'api_version', 'argv', 'base_exec_prefix', 'base_prefix', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'exitfunc', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'ps3', 'py3kwarning', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions']
# file: arg.py
import sys
print sys.argv
# python arg.py -l -a -v a b c
import getopt
argv = '-a -b -c123 -d 456 spam and ham' #가상으로 만든 sys.argv로 받은 명령행 옵션 문자열
#argv = sys.argv[1:] <-- 실제로 만드는 방법
args = argv.split() # 공백으로 분리 및 간 단어를 지닌 리스트 생성
print args
print
optlist, args = getopt.getopt(args, 'abc:d:') # a, b는 추가 인수가 없음을 나타냄
print optlist # c:, d:는 추가 인수가 존재함을 나타냄
print args # 옵션을 처리하고 남아있는 명령행 인수들
['-a', '-b', '-c123', '-d', '456', 'spam', 'and', 'ham'] [('-a', ''), ('-b', ''), ('-c', '123'), ('-d', '456')] ['spam', 'and', 'ham']
a = [1, 2, 3, 4, 5]
b = range(10)
print a
print b
[1, 2, 3, 4, 5] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a = [0] * 10
a
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
N = [20, 15, 39, 2, 7, 5, 223, 75, 46, 87]
M = [3, 5, 9, 2, 7]
L = [None] * 10
for k in M:
L[k] = k * N[k]
print L
[None, None, 78, 6, None, 25, None, 525, None, 783]
mat = [ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
print mat
print mat[1][2]
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] 6
mat = [[0] * 4] * 3
mat
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
mat[0][0] = 100
mat
[[100, 0, 0, 0], [100, 0, 0, 0], [100, 0, 0, 0]]
mat = []
for x in range(3):
mat.append( [0] * 4)
print mat
mat[0][0] = 100
print mat
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] [[100, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
mat = [ [0]*4 for x in range(3)]
print mat
mat[0][0] = 100
print mat
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] [[100, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
from array import *
a = array('i')
print a
a = array('i', range(10))
print a
a = array('i', [0] * 10)
print a
b = array('c', "Hello Python")
print b
print b[0], b[1]
array('i') array('i', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) array('i', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) array('c', 'Hello Python') H e
from array import *
a = array('i')
a.append(1)
a.append(4)
print a
a.insert(1,2) # 인덱스 1 위치에 2 값 넣기
print a
a.extend(array('i', [1, 2, 3, 4, 5]))
print a
array('i', [1, 4]) array('i', [1, 2, 4]) array('i', [1, 2, 4, 1, 2, 3, 4, 5])
a = array('i', [1, 2, 3, 4, 5])
print a[0]
print a[-1]
print a[1:3]
print a[1:-1]
print
del a[0]
print a
print
del a[:3]
print a
1 5 array('i', [2, 3]) array('i', [2, 3, 4]) array('i', [2, 3, 4, 5]) array('i', [5])
from numpy import *
a = array(((1,2,3), (4,5,6), (7, 8, 9))) # 3*3 행렬 생성
print a
print
b = zeros((3,3))
print b
print
c = ones((3,3))
print c
print
d = a * c
print d
print
e = dot(a, c)
print e
print
f = a + c
print f
print
from numpy.linalg import *
g = inv(a)
print g
print
h = eig(a)
print h
print
[[1 2 3] [4 5 6] [7 8 9]] [[ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.]] [[ 1. 1. 1.] [ 1. 1. 1.] [ 1. 1. 1.]] [[ 1. 2. 3.] [ 4. 5. 6.] [ 7. 8. 9.]] [[ 6. 6. 6.] [ 15. 15. 15.] [ 24. 24. 24.]] [[ 2. 3. 4.] [ 5. 6. 7.] [ 8. 9. 10.]] [[ -4.50359963e+15 9.00719925e+15 -4.50359963e+15] [ 9.00719925e+15 -1.80143985e+16 9.00719925e+15] [ -4.50359963e+15 9.00719925e+15 -4.50359963e+15]] (array([ 1.61168440e+01, -1.11684397e+00, -1.30367773e-15]), array([[-0.23197069, -0.78583024, 0.40824829], [-0.52532209, -0.08675134, -0.81649658], [-0.8186735 , 0.61232756, 0.40824829]]))
import glob
print glob.glob('./[0-9].*')
print glob.glob('*.gif')
print glob.glob('?.gif')
print glob.glob('*.ipynb')
print glob.glob('*.i*')
print glob.glob('*')
[] [] [] ['assignment-1.ipynb', 'assignment-2.ipynb', 'cal.ipynb', 'python01.ipynb', 'python02.ipynb', 'python03.ipynb', 'python04.ipynb', 'python05.ipynb', 'python06.ipynb', 'python07.ipynb', 'python08.ipynb', 'Untitled0.ipynb'] ['assignment-1.ipynb', 'assignment-2.ipynb', 'cal.ipynb', 'python01.ipynb', 'python02.ipynb', 'python03.ipynb', 'python04.ipynb', 'python05.ipynb', 'python06.ipynb', 'python07.ipynb', 'python08.ipynb', 'Untitled0.ipynb'] ['assignment-1.ipynb', 'assignment-2.ipynb', 'cal.ipynb', 'cal.py', 'docstring.py', 'docstring.pyc', 'getopt_test.py', 'images', 'modfile.py', 'modfile.pyc', 'python01.ipynb', 'python02.ipynb', 'python03.ipynb', 'python04.ipynb', 'python05.ipynb', 'python06.ipynb', 'python07.ipynb', 'python08.ipynb', 'README.md', 'Untitled0.ipynb']
import glob
import os
flist = glob.glob('*')
for fname in flist:
if os.path.isfile(fname):
print fname, 'is a regular file.'
elif os.path.isdir(fname):
print fname, 'is a dir'
elif os.path.islink(fname):
print fname, 'is a symbolic link'
assignment-1.ipynb is a regular file. assignment-2.ipynb is a regular file. cal.ipynb is a regular file. cal.py is a regular file. docstring.py is a regular file. docstring.pyc is a regular file. getopt_test.py is a regular file. images is a dir modfile.py is a regular file. modfile.pyc is a regular file. python01.ipynb is a regular file. python02.ipynb is a regular file. python03.ipynb is a regular file. python04.ipynb is a regular file. python05.ipynb is a regular file. python06.ipynb is a regular file. python07.ipynb is a regular file. python08.ipynb is a regular file. README.md is a regular file. Untitled0.ipynb is a regular file.
print os.path.getsize('python05.ipynb') # 파일의 크기를 얻는다.
t = os.path.getatime('python05.ipynb') # 파일의 최종 접근시간을 얻는다.
print t # 리턴된 시간은 1970년 1월 1일 00시 00분 부터 경과한 초
import time
print time.ctime(t) # 문자열 시간으로 변환
print time.ctime(os.path.getmtime('python05.ipynb')) # 파일의 최종 수정시간을 얻는다 (가장 많이 사용)
print time.ctime(os.path.getctime('python05.ipynb')) # 파일의 생성 시간을 얻는다 (대부분의 경우 getmtime()과 동일).
96388 1411980452.0 Mon Sep 29 17:47:32 2014 Mon Sep 29 17:48:24 2014 Mon Sep 29 17:48:24 2014