본문 바로가기

Python

(69)
[Python|초보] 난수행렬 만들기 n 을 입력받아 0~99 의 난수로 이루어진 n x n 행렬을 반환하기 >>> import numpy as np >>> >>> np.random.randint(0, 100, size=(3, 3)) array([[32, 65, 6], [35, 66, 43], [89, 14, 90]]) >>> np.random.randint(0, 100, size=(2, 2)) array([[87, 7], [22, 97]]) >>> n = int(input()) 4 >>> mat = np.random.randint(0, 100, size=(n, n)) >>> mat array([[53, 62, 9, 84], [62, 22, 75, 72], [86, 68, 43, 14], [97, 59, 20, 84]])
2021년 5월 konlpy 설치시 문제점들 konlpy 를 오랜만에 설치하고 테스트해 보았다. 설치시에 문제점들이 발견되어 정리하여 공유한다. 테스트는 윈도우에서 수행하였고, openjdk 가 (adoptopenjdk를 이용) 깔려 있으며, JAVA_HOME 과 PATH 설정도 되어 있는 상태이다. 1. python 3.7 새롭게 3.7 가상환경을 만들었다. py -3.7 -m venv v3764 해당 가상환경에 들어가서 konlpy 를 설치했다. c:\PYENVS> v3764\Scripts\activate (v3764) c:\PYENVS> pip install konlpy python 인터프리터로 들어가 konlpy 헬로월드를 해 보자. 에러가 발생한다. (v3764) C:\PYENVS>python Python 3.7.9 (tags/v3.7.9..
[Python] TypeError: unsupported operand type(s) for 파이썬 초보가 겪을 수 있는 에러입니다. unsupported operand type : 지원되지 않는 피연산자 타입 으로 번역이 됩니다. 파이썬의 기본연산이 불가능한 타입끼리 연산을 하려고 할 때 발생합니다. 예를 들어, 문자열에 숫자를 더하거나 뺄 수는 없을 것입니다. 이럴 때 발생합니다. 예를 몇 개 봅시다. >>> 1 + "3" Traceback (most recent call last): File "", line 1, in 1 + "3" TypeError: unsupported operand type(s) for +: 'int' and 'str' 숫자 1과 문자열 "3"을 더하려 했기 때문에 에러가 발생했습니다. >>> a = input() 3 >>> a '3' >>> 1 + a Tracebac..
[C,Py|초급] 1부터 1000까지의 합 출력하기 #include int main() { printf("%d", 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+94+95+96+97+98+99+100); return 0; } 누구라도 이해할 수 있는 간단한 코드. 물론 이걸 다 치려면 힘들다. 그래서 파이썬으로 이 소스를 생성..
[EP019] 윤년 1901년 1월부터 2000년 12월까지 중에서 1일이 일요일인 달의 갯수를 구하는 문제. 윤년을 구하는 조건이 주어지고, 그 조건만 잘 써 주고, mod 7을 이용하면 요일을 구할 수 있다. // leap_year.cpp : Defines the entry point for the console application. // /* http://projecteuler.net *____________________________________________________________________ Problem 19 14 June 2002 You are given the following information, but you may prefer to do some research for yourself. ..
파이썬초보 : 숫자계단 >>> 몇줄 = 10 >>> ij = [(i, j) for i in range(몇줄) for j in range(i+1) ] >>> for n, (i, j) in enumerate(ij): if i != 0 and j == 0: print() print(n%10, end='') 0 12 345 6789 01234 567890 1234567 89012345 678901234 5678901234
엘라스틱서치 elasticsearch-dsl 에서 시간조건을 주어 검색하는 방법 filter 함수에 "range"를 주어 추려낸다. client = Elasticsearch() timestamp_range = { "@timestamp": { "gte": "2020-11-01", "lt": "2020-11-02" } } s = Search(using=client, index="my-index") .filter("range", **timestamp_range) src : stackoverflow.com/questions/58453236/query-timestamp-range-using-elasticsearch-dsl-py Query timestamp range using elasticsearch-dsl-py I have an elasticsearch range query that I'd..
[파이썬초보] TypeError: 'NoneType' object is not subscriptable not subscriptable 은 var[ ] 와 같이 생긴 부분에서 에러가 났다는 말임. >>> a = 1 >>> b = 22.1 >>> c = 'abc' >>> c[1] 'b' >>> a[1] Traceback (most recent call last): File "", line 1, in a[1] TypeError: 'int' object is not subscriptable >>> b[1] Traceback (most recent call last): File "", line 1, in b[1] TypeError: 'float' object is not subscriptable 위 예제에서 a[1] 에서 'int' object is not subscriptable 이란 에러가 발생했다. a = ..