오늘/오늘의 함수 12

[Tesorflow] tf.random.categorical()

tf.random.categorical( logits, num_samples, dtype=None, seed=None, name=None ) 순환신경망에서 다음 예측값에 어느정도 확률을 기반으로한 랜덤성을 부여할 때 사용할 수 있다. Params : logits : 2D Tensor [ batch_size, num_classes ], [ i , : ] slice represents unnormalized log-probailities of all classes num_samples : 0-D Number of independent samples of draw for each row slice dtype : Integer type of output, default int64 seed : Integer, r..

[Tensorflow] tf.math.equal, tf.math.not_equal, tf.reduce_all, tf.cond

Tensorflow Graph 안에 If 문 사용하기 위해서 위의 함수를 이용할 수 있다. tf.equal, tf.not_equal Params : x : Tensor, SparseTensor, IndexedSlices y : Tensor, SparseTensor, IndexedSlices name : optional Returns : Tensor, dtype=tf.bool, same size with x, y 설명 : x 와 y 가 같은지 판단해서 bool 타입으로 반환한다. 이때 각각의 원소하나하나씩 판별해서 x, y 와 shape이 동일한 bool 타입 텐서를 반환한다. x = tf.constant([2, 4, 2]) y = tf.constant(2) tf.equal(x, y) # x == y # ..

[tensorflow] tf.math.add_n, tf.math.reduce_mean, tf.cinsum

tf.math.add_n Params : inputs : list of Tensor or tf.IndexedSlices name : name for operation (optional) Returns : tensor_same_shape_with_input_element 설명 : shape이 동일한 텐서 리스트를 받아서 원소별 덧셈을 수행한다. shape 이 동일하지 않거나 dtype이 다르면 ValueError name은 에러발생시 쉽게 찾기위해서 이 특정 연산의 이름을 지정한다. a = tf.constant([[3, 5], [4, 8]]) b = tf.constant([[1, 6], [2, 8]]) c = tf.math.add_n([a, b], name = "operation_name") print(a..

[numpy] np.flip

np.flip Params : m : array_like axis : None or int or tuple of int returns : array_like axis 기준으로 reversed 한 m 의 view 설명 : axis를 정하면 축을 기준으로 원소들을 reversed 한다. 축을 정하지않으면 모든축에 대해서 reversed 한다. A = np.arange(8).reshape((2,2,2)) print(A) ''' array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) ''' print(np.flip(A)) ''' array([[[7, 6], [5, 4]], [[3, 2], [1, 0]]]) ''' print(np.flip(A, 0)) ''' array([[[4, 5], [..

[Python] functools.partial

Python 3.4 버전에서 추가된 기본라이브러리 클래스이다. 인자로 받은 함수객체에 keywords를 지정한 함수처럼 동작하는 새 partial 객체를 반환한다. functools.partial( func , / , *args, **keywords ) from functools import partial from tensorflow import keras FixedConv2D = partial(keras.layers.Conv2D, kernel_size=3, strides=1, padding='same', activation='relu') model.add(FixedConv2D(filters=32)) *args 는 키워드 지정없이 인자를 지정한 경우이고, **keywords는 키워드 지정하여 인자를 지정..

[numpy] np.linspace, np.meshgrid np.logspace

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0) Parameters : start : array_like stop : array_like num : int, optional endpoint : bool, optional retstep : bool, optional dtype : dtype, optional axis : int , optional Returns : samples : ndarray step : float, optional start ~ stop 까지 num 개수만큼 intervel 을 생성한다. endpoint =False : stop 을 포함하지 않고 num 개수 만큼 intervel ..

[numpy] np.cumsum, np.concatenate

numpy.cumsum(a, axis=None, dtype=None, out=None) Parameters : a : array_like axis : int, optional dtype : dtype, optional out : ndarray, optional Returns : cumsum_along_axis : ndarray 설명 : a 행렬의 각 원소를 차례로 더한 1차원 배열을 반환한다. axis는 특정 축을 지정할 수 있고, 없으면 모든 원소를 차례대로 더한다. dtype : 반환배열의 원소 데이터 타입 out : 반환배열을 지정한다. a = np.array([[1,2,3], [4,5,6])]) np.cumsum(a) #[1, 3, 6, 10, 15, 21] np.cumsum(a, axis=0) ..

[pickle] pickle.dump, pickle.load , pickle.dumps, pickle.loads

머신러닝사용시 다차원 데이터를 바이너리 형식으로 저장 및 로드하는 함수. pickle.dump(obj, file, protocol=None, *, fix_imports=True, buffer_callback=None) = Pickler(file, protocol).dump(obj). 파이썬 object를 bytes 형식으로 디스크 python file object에 저장한다. pickle.dumps(obj, protocol=None, *, fix_imports=True, buffer_callback=None) 파이썬 object를 bytes 형식으로 디스크 대신 메모리에 적재한다. protocol : https://docs.python.org/3/library/pickle.html#data-stream-..