본문 바로가기

블로그/Python

[python] 리스트 내포(List comprehension)란? 리스트 내포는 파이썬 답게(Pythonic) 리스트를 만드는 방법이다. 일반적으로 list 만드는 방법을 통해 10개의 제곱수를 만드는 코드를 작성해보자. squares = [] for i in range(10): squares.append(i * i) squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] 위 코드는 제곱한 수를 squares라는 리스트에 담는 예제이다. 이것을 리스트 내포(list comprehension)을 활용하면 다음과 같이 간단히 해결할 수 있다. squares = [i * i for i in range(10)] squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] 일반적으로 list에 대한 조건으로 filter() 를 활용해.. 더보기
Google Colab 코랩 런타임 유지 개발자도구를 열고 Console에 아래 코드를 입력하면 Colab 내 "리소스"를 주기적으로 클릭해서 Colab에서 세션이 끊어지는 것을 방지해준다. function ConnectButton(){ console.log("Connect pushed"); document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click() } setInterval(ConnectButton,60000); 참고: https://modernflow.tistory.com/12 더보기
AttributeError: 'TensorVariable' object has no attribute 'get_shape' 해결 Keras에서 사용하는 Backend가 "Theano"를 사용했기 때문에 발생한 문제이다. 내가 실행하려고 하는 딥러닝 아키텍처가 Tensorflow Backend 기반으로 작성되었기에 발생하는 오류 get_shape()를 int_shape()로 변경해보고, 뭐시기를 다 해봤는데 안되더라. 코드가 get_shape().as_list()로 들어가는데, get_shape()를 변경하면, as_list()가 없다더라.. 벡앤드를 우선 체크해보자. backend Keras is a model-level library, providing high-level building blocks for developing deep learning models. It does not handle low-level operat.. 더보기