본문 바로가기

IT/Python30

사진을 보고 낮인지 저녁인지 간단한 코드로 판단 사진 input으로 nxn 행렬이 들어 온다. n 은 'Blue,Green, Red' 각 B, G, R은 0~255 RGB채널이다. 예를들어, 90,90,50 90,90,10 255,255,255 100,100,88 80,80,80 15,75,255 ... 이렇게 값이 들어오는 사진이 있다면, 이 사진이 낮에 찍은 것인지, 밤에 찍은 것인지 판단해보자. 아래 파이썬코드로 헀을 시, 정밀하지 않지만 대충 잘 판별이 된다. result = [] while True: try: data = [[int(j) for j in i.split(',')] for i in input().split(' ')] for k in range(len(data)): adder = 0 for m in range(3): adder +=.. 2018. 2. 20.
matplotlib 라이브러리 사용할 때 imread() 오류 import matplotlib에서 imread()함수 사용할 때 아래와 같은 오류가 나왔다. ValueError: Only know how to handle extensions: [u'png']; with Pillow installed matplotlib can handle more images command명령으로 가서 pip install pillow 를 설치해주면 해결된다. 2018. 2. 20.
numpy 설치, basic pip install numpy 를 사용해서 설치한다. 1. numpy.array, numpy.aragnenumpy.array 생성자를 사용해서 기본 array를 생성할 수 있다. numpy.arange(n) n 수 만큼 숫자를 배열한다. 2. numpy.linspace(start, end, length) - 일정한 간격으로 수를 생성한다. 3. ones, zeros 4. numpy.eye, numpy.diag 5. numpy.random.rand - 난수 발생 - 난수 발생시 비슷한 숫자가 계속나오면 seed를 바꿔준다. seed값을 time second에 따라 바꿔주면 중복이 별로 없는 난수가 발생한다. 6. array 형식 변환 numpy.astype() 7. array masking 방법 - 배열.. 2018. 2. 20.
pandas 기초, series 2008년 Web McKinney가 pandas를 만들었다. python을 R처럼 데이터 구조를 잘 볼 수 있고 제어할 수 있도록 만든 것이다. pandas의 기본 데이터 구조는 -Series -DataFrame -Panel 로 되어 있다. 1. Series- Series는 1차원 Numpy 배열로 이해할 수 있다. Series는 배열라벨로 이루어진 numpy배열이다. - ndarray or dictionary or scalar value 중 하나가 될 수 있다. ######################### ndarray examples ######################### # 1.0 random series = pd.Series(np.random.rand(5)) print(series) Ou.. 2018. 2. 20.
반응형