import numpy as np
np.array( [1, 4, 5, 8], float )
- data type은 numpy.ndarray
- python standard library에 있는 list와 유사하게 생겼지만, data type은 numpy.ndarray임
- np.array( [1, [4, 5] )와 같이 입력하면 error 발생함.
- parameter는 only list type으로 넣어야 됨.
- dtype = 'i' : int32 / 'i8' : int64 / 'f' : float32 / 'f8' : float64/ 'U' : <Ux / 'U4' : <U4 (slice로도 이용)
- bold는 default임
np.zeros( array size - tuple )
np.ones( array size - tuple )
- default dtype 은 float임. array size만큼 0 또는 1을 채움
- np.zeros(5, dtype = 'U4') 를 하면, 빈 string의 ndarray를 만들 수 있음. (max string 4글자로 제한)
np.ones_like(b, dtype = 'f')
np.zeros_like(b, dtype = 'f')
- dtype 지정안하면 original data의 dtype을 따름
np.full( array size - tuple, value)
- array size의 ndarray에 value로 채움
np.eye( array size - tuple 아님!!)
- Identity matrix (square matrix만 해당)
np.emtpy( array size - tuple)
- 메모리 값으로 matrix 생성, 시간 단축할 수 있음
np.arange( a, b, c )
- range( )와 유사함
np.linspace( a, b, c )
np.logspace( a, b, c )
- linear space / log space 구간을 c개로 분할
np.random.random( array size - tuple )
- [0, 1) float random number를 ndarray로 return
np.random.rand( array size - tuple 아님!!)
- random.random이랑 동일한데 input parameter가 tuple이 아님
np.random.uniform( a, b, array size - tuple )
- [a, b) float random number
np.random.randint( a, b, ( c, d ) )
- [a, b) integer random number return
- b 없으면 [0, a) integer random number return
- size = ( c , d ) / ( c , d ) / size = c / c 다 됨
- np.random.random_integer( ) : [a, b] integer random number, version3.7부터 deprecated됨.
np.random.randn( array size - tuple 아님!!)
- standard normal distribution ~ N(0, 1)
- mu / sigma 포함하고 싶으면, 아래처럼.
np.random.normal(mean, std, (shape))
- normal distribution ~ N(mean, std)
'공부는 언제까지 해야 하나' 카테고리의 다른 글
[Python] pandas module - Series object (0) | 2021.02.03 |
---|---|
[Python] numpy module - File IO (0) | 2021.02.03 |
[Python] numpy module - matrix operation (0) | 2021.02.03 |
[Python] numpy module - mathematics / statistics (0) | 2021.02.03 |
[Python] numpy module - manipulation (0) | 2021.02.03 |