파이썬 Matplotlib plot numpy matrix as 0 index
numpy 행렬을 준비한 다음 matplotlib를 사용하여 다음과 같이 행렬을 플로팅합니다. >>> import numpy >>> import matplotlib.pylab as plt >>> m = [[0.0, 1.47, 2.43, 3.44, 1.08, 2.83, 1.08, 2.13, 2.11, 3.7], [1.47, 0.0, 1.5, 2.39, 2.11, 2.4, 2.11, 1.1, 1.1, 3.21], [2.43, 1.5, 0.0, 1.22, 2.69, 1.33, 3.39, 2.15, 2.12, 1.87], [3.44, 2.39, 1.22, 0.0, 3.45, 2.22, 4.34, 2.54, 3.04, 2.28], [1.08, 2.11, 2.69, 3.45, 0.0, 3.13, 1.76, 2.46..
2020. 12. 25.
파이썬 Python은 동시에 두 목록을 반복합니다.
파이썬에서 두 개 이상의 목록을 동시에 반복하는 방법이 있습니까? 같은 것 a = [1,2,3] b = [4,5,6] for x,y in a,b: print x,y 출력하다 1 4 2 5 3 6 다음과 같은 튜플을 사용하여 할 수 있다는 것을 알고 있습니다. l = [(1,4), (2,5), (3,6)] for x,y in l: print x,y 해결 방법 for x, y in zip(a, b): 데모: >>> a = [1,2,3] >>> b = [4,5,6] >>> for x, y in zip(a, b): ... print x, y ... 1 4 2 5 3 6 참조 페이지 https://stackoverflow.com/questions/21098350
2020. 12. 25.
파이썬 python select specific elements from a list
목록에서 특정 값만 가져 오는 "pythonic"방법이 있습니까?이 펄 코드와 유사합니다. my ($one,$four,$ten) = line.split(/,/)[1,4,10] 해결 방법 operator.itemgetter 를 찾고 있다고 생각합니다. import operator line=','.join(map(str,range(11))) print(line) # 0,1,2,3,4,5,6,7,8,9,10 alist=line.split(',') print(alist) # ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] one,four,ten=operator.itemgetter(1,4,10)(alist) print(one,four,ten) # ('1', '..
2020. 12. 25.