Road to Data Analyst
-
[Project Euler] Q5. Smallest multipleRoad to Data Analyst/Python 2022. 6. 6. 09:37
Q5 : 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? 처음 아이디어 - 조건문을 통한 1~20 나머지 (%)가 0인 숫자 찾기 (1~20에서 소수만 조건문에 포함시키면 될 것 같다.) - 반복문을 통한 숫자 계속 증가 (20부터), 조건문에 맞는 값 나오면 탈출 그 다음 아이디어 - 파이썬에 있는 math함수를 활용하여, 1~20사이에 있는 모든 수의 최소공배수를 구하면 될 것 같다는 생..
-
[Project Euler] Q4 : Largest palindrome productRoad to Data Analyst/Python 2022. 6. 4. 08:51
Q4 : A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. 문제 : 세자리 숫자를 곱하여 나오는 대칭수 중 최댓값을 찾아야 함. (1) 최소 다섯자리 (100 * 100 = 10,000) 부터 여섯자리 (999 * 999 = 998,001) 중에서 대칭수를 찾고 (2) 그 중 최댓값을 구해야 함 (1) 최소 다섯자리 (100 * 100 = 10,000) 부터 여섯자리 (999 * 999 ..
-
[NumPy] 배열 값 삽입/수정/삭제/복사Road to Data Analyst/Python 2022. 5. 31. 00:19
배열 값 삽입 : insert() 1. 코드 import numpy as np a2 = np.array([[1,2,3], [4,5,6], [7,8,9]]) print(a2) b2 = np.insert(a2, 1, 10, axis=0) print(b2) c2 = np.insert(a2, 1, 10, axis=1) print(c2) 2. 결과 - axis 값을 입력하지 않을 경우, axis = 0으로 인식, 1차원 배열로 출력한다 - 특정 row/column/depth 전체에 값을 삽입하는 것으로 생각하면 된다. 배열 값 수정 - fancy indexing을 활용하자 - 2차원 배열인 a2를 'a2[0]=1'와 같이 작성할 경우 0은 0번째 row의 값을 모두 1로 변경한다. - 원본에는 영향 X 배열 값 ..
-
[NumPy] 불리언 인덱싱(Boolean Indexing)Road to Data Analyst/Python 2022. 5. 27. 12:10
불리언 인덱싱 : True인 값만 조회하는 것 1. 코드 import numpy as np a = np.array([[1,2,3], [4,5,6], [7,8,9]]) bi = np.random.randint(0,2, (3,3), dtype=bool) print(a) print(bi) print(a[bi]) 2. 결과 (1) 우선 numpy를 불러온다. (2) 그리고 적당한 size의 array를 만든다. (위의 경우 (3,3)) (3) True, False 형태, (3,3) 사이즈의 배열을 하나 더 만든다. (4) print(a[bi]) : 배열 각 요소에 True인 부분 값만 출력한다. * 활용 : 특정 조건에 맞추어 결과를 필터링할 때 활용된다. 출처 : 이수안 컴퓨터 연구소
-
[Project Euler] Q3. Largest prime factorRoad to Data Analyst/Python 2022. 5. 27. 09:13
Q3 : The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143? 구현해야 하는 부분 1. 소인수분해 2. 최댓값 1. 소인수 분해 : 2^3처럼 동일 숫자 반복될 수 있으니, 반복문 사용하여 소인수분해하기 2. 최댓값 : 리스트로 받고 있었던 인수들 중 최댓값 (max) 구하기 factors = [] n = 2 find = 600851475143 while n