[Python] np.random - 난수 생성하기
오늘은 numpy로 난수를 생성하는 random 함수에 대해 포스팅하겠다. np.random.rand() 0 이상 1 미만의 범위 내에 주어진 argument 만큼 난수를 생성한다. import numpy as np np.random.rand(3) # array([0.60407304, 0.97595625, 0.3530597 ]) np.random.rand(3,3) """ array([[0.95799066, 0.43424117, 0.59480775], [0.93778055, 0.97494792, 0.81196245], [0.15744564, 0.05079325, 0.562474 ]]) """ argument가 1개로 들어가면 1-d 형태로 난수를 생성하며 2개를 입력하면 2-d 형태로 난수를 생성한다. n..
2022. 9. 12.
[Python] for loop - enumerate, zip 사용
오늘은 python for 문에 빠질 수 없는 enumerate와 zip에 대해 포스팅을 하고자한다. enumerate enumerate를 직역하자면 숫자를 센다는 의미로 for문이 몇번 돌아갔는지 카운트를 해주는 내장 함수이다. [enumerate] 다음과 같이 사용이 되며 0부터 시작한다. import numpy as np linspace_array_1 = np.linspace(1,100,10) for num, value in enumerate(linspace_array_1): print('count: {}, value: {}'.format(num,value)) """ count: 0, value: 1.0 count: 1, value: 12.0 count: 2, value: 23.0 count: 3,..
2022. 9. 9.