[Python|초보] 난수행렬 만들기
n 을 입력받아 0~99 의 난수로 이루어진 n x n 행렬을 반환하기 >>> import numpy as np >>> >>> np.random.randint(0, 100, size=(3, 3)) array([[32, 65, 6], [35, 66, 43], [89, 14, 90]]) >>> np.random.randint(0, 100, size=(2, 2)) array([[87, 7], [22, 97]]) >>> n = int(input()) 4 >>> mat = np.random.randint(0, 100, size=(n, n)) >>> mat array([[53, 62, 9, 84], [62, 22, 75, 72], [86, 68, 43, 14], [97, 59, 20, 84]])
Connected Component
>>> data = [("ㄱ","ㄴ"), ("ㄴ","ㄷ"), ("ㄷ","ㄱ"), ("ㄱ","ㄴ"), ("ㄹ","ㅁ"), ("ㅂ","ㅅ"), ("ㅇ","ㄹ")] >>> data [('ㄱ', 'ㄴ'), ('ㄱ', 'ㄷ'), ('ㄴ', 'ㄷ'), ('ㄹ', 'ㅁ'), ('ㄹ', 'ㅇ'), ('ㅂ', 'ㅅ')] >>> class ConnectedGroups: def __init__(self): self.groups = [] # groups remain mutually exclusive def add(self, e): set_e = set(e) overlap_index = [] for i, g in enumerate(self.groups): if set_e & g: overlap_index.append(i) if..