-
[python] timeit 모듈을 사용한 numpy 배열 제곱 비교아무거나적어~ 2023. 7. 29. 17:21
제곱만 하는 경우에는 np.power 는 사용하지 말자(느림)
123456789101112131415161718192021import numpy as npX = np.arange(100).reshape((10, 10))def a(N):return np.power(N, 2)def b(N):return X*Xdef c(N):return X**2def d(N):return np.square(X)if __name__ == '__main__':import timeitprint(timeit.timeit("a(X)", number=1000, globals=globals()))print(timeit.timeit("b(X)", number=1000, globals=globals()))print(timeit.timeit("c(X)", number=1000, globals=globals()))'아무거나적어~' 카테고리의 다른 글
[python] '리스트 공간 확보 후 원소 대입'과 'list.append를 이용한 원소 삽입' 간 수행 시간 차이 (0) 2023.07.29 [jupyter] !, % command 차이 (0) 2023.07.29 [python] timeit 모듈을 사용한 리스트 생성 수행시간 비교 (0) 2023.07.29 [c++] bool operator() (0) 2023.07.17 vscode c++20 (0) 2023.07.16