본문 바로가기

컴퓨터공학/python

(18)
[Numpy] Axis and Keepdims Arguments 이번 글에서는 sum연산을 통해 axis와 keepdims에 대해 간단히 알아보도록 하겠습니다. Index 1. Axis 2.keepdims 1. Axis x.sum(axis =option)에서 option은 0부터 n까지 설정할 수 있으며 해당 되는 값의 차원의 합을 구하며 동시에 제거합니다. 예시를 통해 3rd order tensor에 대하여 axis별 연산을 설명해 보도록 하겠습니다. import numpy as np a= np.arange(2*3*4).reshape((2,3,4)) print(a,a.shape) [[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16 17 18 19] [20 21 22 23]]] (2, 3, 4) #ex1) sum_0 ..
[Numpy] Indexing and Slicing 이번 글에서는 ndarray의 Indexing 에 대해서 알아보도록 하겠습니다. reference https://numpy.org/doc/stable/reference/arrays.indexing.html Indexing — NumPy v1.21 Manual When there is at least one slice (:), ellipsis (...) or newaxis in the index (or the array has more dimensions than there are advanced indexes), then the behaviour can be more complicated. It is like concatenating the indexing result for each advanced i..
[Numpy] General Broadcasting Rules에 대하여 (작성중) 이번 글에서는 Broadcasting에 대해서 다뤄보도록 하겠습니다. Reference https://numpy.org/doc/stable/user/basics.broadcasting.html Broadcasting — NumPy v1.21 Manual The term broadcasting describes how numpy treats arrays with different shapes during arithmetic operations. Subject to certain constraints, the smaller array is “broadcast” across the larger array so that they have compatible shapes. Broadcasting provi num..
[Numpy] Data type에 대하여 이번 글에서는 넘파이의 Data type에 대해서 알아보도록 하겠습니다. Reference https://numpy.org/doc/stable/user/basics.types.html Data types — NumPy v1.21 Manual Array Scalars NumPy generally returns elements of arrays as array scalars (a scalar with an associated dtype). Array scalars differ from Python scalars, but for the most part they can be used interchangeably (the primary exception is for versions of Python numpy...
[Numpy] ndarray를 알아보자2(reshape, resize,copy,view) 이번 글에서는 ndarray의 reshape , resize, copy, view에 대해 알아보도록 하겠습니다. 1. numpy.reshape(a,newshape,order='c') np.reshape은 원하는 tensor의 형태로 변환해주는 API입니다. 아래는 shape (,6) 을 shape (2,3)으로 변환해주는 예시 코드와 결괏값입니다. import numpy as np a= np.arange(6) b= np.reshape(a,(2,3)) print("original ndarray: \n",a) print("reshaped ndarray: \n",b) original ndarray: [0 1 2 3 4 5] reshaped ndarray: [[0 1 2] [3 4 5]] print("origi..
[Numpy] ndarray에 대해 이번 글에서는 Numpy의 ndarray에 대해서 알아보겠습니다. Reference - numpy공식 문서 https://numpy.org/doc/stable/reference/arrays.ndarray.html The N-dimensional array (ndarray) — NumPy v1.21 Manual Arithmetic and comparison operations on ndarrays are defined as element-wise operations, and generally yield ndarray objects as results. Each of the arithmetic operations (+, -, *, /, //, %, divmod(), ** or pow(), , &, ^, |,..
[python] 파이썬이 동작하는 방식에 대해서2 (가상머신) 이번 글에서는 파이썬이 소스코드를 동작시키는 과정을 살펴보도록 하겠습니다. 이런 다이어그램을 보신적이 있으신가요? 컴파일러가 인터프리터안에 포함되어있는걸 보고 놀라지 않으셨으면 좋겠습니다. 인터프리터는 컴파일러와 가상머신이라는 두 부분으로 나누어져 있기때문입니다. 그렇다면 컴파일러가 하는 일은 무엇일까요? 컴파일러는 우리가 작성한 소스 코드를 바이트 코드로 변환시켜 주는 역할을 합니다. 바이트코드란? lower level 코드이며 플랫폼에 독립적이며 소스코드를 내부적으로 저장하고있죠. 그렇다면 파이썬 가상머신(PVM)란 무엇일까요? 바로 파이썬의 런타임 엔진입니다. 다시말해 PVM은 python 시스템의 일부이기 때문에 별도의 설치가 필요하지 않고 항상 존재합니다. 그럼 본격적으로 소스코드를 동작시키는 ..
[python] 파이썬이 동작하는 방식에 대해서 1 이번 글에서는 파이썬이 동작하는 방식에 대해서 알아보도록 하겠습니다. Reference https://indianpythonista.wordpress.com/2018/01/04/how-python-runs/ How Python runs? First article of 2018 is up! And I decided to go with a very subtle topic this time. Have you ever thought how the Python code is actually executed by the Python interpreter? What steps are carried… indianpythonista.wordpress.com 알아보기에 앞서 가상머신과 커널 그리고 쉘에 대해 간단하게 알아..