프로그래밍 언어/파이썬 python

프로그래밍 언어/파이썬 python

[Python] Numpy Array 특정 행 특정 열만 계산하는 방법

import numpy as np list_1 = [[1,2,3,4,5], [6,7,8,9,10]] list_2 = [[11,12,13,14,15]] list_3 = [[16,17,18,19,20]] array_1 = np.array(list_1) array_2 = np.array(list_2) array_combine = np.concatenate([array_1, array_2, list_3], axis=0) print(array_combine, array_combine.shape) print(array_combine[0]) print(array_combine[0].sum()) print(array_combine[3,:]) print(array_combine[3,:].sum()) print(array..

프로그래밍 언어/파이썬 python

[Python] Numpy 행별 합계값을 기존 배열에 추가하는 방법

import numpy as np list_1 = [[1,1,1,1,1], [2,2,2,2,2]] list_2 = [[3,3,3,3,3]] list_3 = [[4,4,4,4,4]] array_1 = np.array(list_1) array_2 = np.array(list_2) array_combine = np.concatenate([array_1, array_2, list_3], axis=0) print(array_combine, array_combine.shape) array_row_sum = array_combine.sum(axis=1) print(array_row_sum, array_row_sum.shape) array_row_sum_reshape = array_row_sum.reshape((len..

프로그래밍 언어/파이썬 python

[Python] Numpy Array 두개 합치는 방법

import numpy as np temp_list_1 = [[1,2,3,4,5], [6,7,8,9,10]] temp_np_array_1 = np.array(temp_list_1) temp_list_2 = [[1,1,1,1,1], [2,2,2,2,2]] temp_np_array_2 = np.array(temp_list_2) print(temp_np_array_1) print(temp_np_array_2) print("행방향으로 합치기") array_row = np.concatenate([temp_np_array_1, temp_np_array_2], axis=0) print(array_row, array_row.shape, array_row.dtype) print("열방향으로 합치기") array_colu..

프로그래밍 언어/파이썬 python

[Python] Numpy 행별 열별 max, min, sum, mean 구하는 방법

#1 행별, 열별 합 #2 행별, 열별 최대값 #3 행별, 열별 최소값 #4 행별, 열별 평균 #1 행별, 열별 합 import numpy as np temp_list = [[1,3,5,7,9], [2,4,6,8,10]] temp_np_array = np.array(temp_list) print(temp_np_array, temp_np_array.shape) print(temp_np_array.sum(axis=1)) print(temp_np_array.sum(axis=0)) #2 행별, 열별 최대값 import numpy as np temp_list = [[1,3,5,7,9], [2,4,6,8,10]] temp_np_array = np.array(temp_list) print(temp_np_array, ..

프로그래밍 언어/파이썬 python

[Python] Numpy 모든 요소의 max, min, sum, mean 구하는 방법

import numpy as np temp_list = [[1,3,5,7,9], [2,4,6,8,10]] temp_np_array = np.array(temp_list) print(temp_np_array, temp_np_array.shape) print(temp_np_array.sum()) print(temp_np_array.max()) print(temp_np_array.min()) print(temp_np_array.mean())

프로그래밍 언어/파이썬 python

[Python] 1차원,2차원,3차원 리스트를 numpy array로 변경하는 방법

#1 1차원 리스트를 넘파이 어레이로 #2 2차원 리스트를 넘파이 어레이로 #3 3차원 리스트를 넘파이 어레이로 #1 1차원 리스트를 넘파이 어레이로 import numpy as np temp_list = [1,3,5,7,9] temp_np_array = np.array(temp_list) print(temp_list, type(temp_list), len(temp_list)) print(temp_np_array, type(temp_np_array), len(temp_np_array), temp_np_array.shape) #2 2차원 리스트를 넘파이 어레이로 import numpy as np temp_list = [[1,3,5,7,9], [2,4,6,8,10]] temp_np_array = n..

프로그래밍 언어/파이썬 python

[Python] numpy로 랜덤 데이터 고정하는 방법

#1 랜덤 사용 #2 랜덤 여러번 출력 #3 랜덤 반복문에서 출력 #4 랜덤 고정 #1 랜덤 사용 import numpy as np random_list = np.random.randint(5, size=3) print(random_list) #2 랜덤 여러번 출력 import numpy as np random_list = np.random.randint(5, size=3) print(random_list) print(random_list) print(random_list) #3 랜덤 반복문에서 출력 import numpy as np for _ in range(5): random_list = np.random.randint(5, size=3) print(random_list) #4 랜덤 고정 import..

프로그래밍 언어/파이썬 python

[Python] string to datetime (yyyy-mm-dd *)

#1 yyyy-mm-dd 문자열을 datetime 타입으로 변경 #2 yy-mm-dd 문자열을 datetime 타입으로 변경 #3 yyyy-mm-ddTHH:MM:ss 문자열을 datetime 타입으로 변경 #4 yyyy-mm-dd HH:MM:ss 문자열을 datetime 타입으로 변경 #1 yyyy-mm-dd 문자열을 datetime 타입으로 변경 from datetime import datetime str_1 = "2023-01-07" print(str_1, type(str_1)) dt_1 = datetime.strptime(str_1, "%Y-%m-%d") print(dt_1, type(dt_1)) #2 yy-mm-dd 문자열을 datetime 타입으로 변경 from datetime import da..

프로그래밍 언어/파이썬 python

[Python] timeit 사용하는 방법

#1 for문 속도 측정하기 #1 for문 속도 측정하기 import timeit def test_for(): for i in range(100): i += 1 t1 = timeit.repeat(stmt='test_for()', setup='from __main__ import test_for', number=10000, repeat=3) print(t1)

프로그래밍 언어/파이썬 python

[Python] isinstance()로 데이터 타입 확인하는 방법

#1 str 타입 확인하기 #2 int 타입 확인하기 #3 float 타입 확인하기 #4 list 타입 확인하기 #5 dict 타입 확인하기 #6 set 타입 확인하기 #7 tuple 타입 확인하기 #1 str 타입 확인하기 temp_str = "park" temp_int = 15 temp_float = 1.53 temp_list = [1, 2] temp_dict = {"a": 1, "b": 2} temp_set = {1,2,3} temp_tuple = (1,2,3) print(isinstance(temp_str, str)) print(isinstance(temp_int, str)) print(isinstance(temp_float, str)) print(isinstance(temp_list, str))..

박경태
'프로그래밍 언어/파이썬 python' 카테고리의 글 목록