numpy의 스타일, 랜덤값(정수는 어떻게 하는지) 질문
우선 설명에 나와있듯이,
예를들어 numpy.zeros(6, dtype=int)로 되어있는데요.
여기서 dtype = int가 아니라, dtype=int 처럼 붙여쓰는 것이 정석적인 스타일인지요?
어떤 괄호 안의 파라미터부분은 저렇게 붙여서 쓰는것이 보편적인가요?
numpy.random(6)을 하면 결과가 6개의 실수가 나옵니다.
이를 정수로 바꾸고 싶어서 dtype=int를 추가해보았으나 에러가 뜨네요.
랜덤한 정수값을 가지도록 array를 만들 수는 없을까요?
정석적인 파이썬 코딩 스타일을 권고하고 있는 가이드인 PEP8에 따르면, 파라미터는 다음과 같이 쓰는 것을 권하고 있어요!
Don't use spaces around the = sign when used to indicate a keyword argument, or when used to indicate a default value for an unannotated function parameter.
Yes
:
def complex(real, imag=0.0):
return magic(r=real, i=imag)
No
:
def complex(real, imag = 0.0):
return magic(r = real, i = imag)
랜덤의 int값을 뽑아주는 numpy.random.randint를 사용하는 것이 좋을 거 같아용
randint
의 파라미터중 size를 조정하면, array형태로도 만들수 있습니다
import numpy as np
np.random.randint(10, size=6)
array([9, 7, 3, 1, 0, 7])
댓글 5개
댓글 1개