Programming(72)
-
numpy array
numpy에서의 배열 선언 방법 우선 numpy를 import import numpy as np 4x2 행렬 선언 방법들 np.ones((4, 2)) # shape 객체를(튜플로) 입력으로 받기 때문에 괄호 필요 array([[1., 1.], [1., 1.], [1., 1.] [1., 1.]]) 이외에 np.zeros((4, 2))는 모든 값이 0으로 채워진 배열을 생성합니다. 파이썬 리스트를 넘파이 배열로 변환 원래 있던 파이썬 배열을 numpy 배열로 변환할 수도 있습니다. arr = np.array([[1, 2], [3, 4], [5, 6]]) print(arr) array([[1, 2], [3, 4] [5, 6]]) 배열 선언 시 원소의 type을 지정 arr = np.array([[1, 2], ..
2023.09.05 -
numpy frombuffer
numpy를 사용해 binary file을 읽는 것은 numpy.readbuffer를 통해 가능합니다. 이를 사용하면 버퍼 내 내용을 1차원 배열로 만들어 줍니다. numpy.frombuffer(buffer, dtype=float, count=-1, offset=0) buffer: 입력 binary data dtype: datatype count: data 수 (-1 지정 시 전체 read) offset: start offset ex. data = b'\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8' np_data = numpy.frombuffer(data, dtype=numpy.float32) print(np_data)[-7.0965486e-17 -1.8612995e-14]
2023.09.05 -
Python glob
glob ? 특정 경로 내 파일들 중 특정 조건으로 필터링하여 파일들의 목록을 획득하고자 할 때 사용합니다. Usage 특정 폴더 내 모든 파일의 목록을 획득 합니다. recursive에 True를 설정하면 하위의 모든 폴더들에서도 재귀적으로 파일을 탐색합니다. import glob glob.glob('mydir/*.jpg', recursive=True) print(glob)['mydir/file1.jpg', 'mydir/file2.jpg']regular expression을 지원하기에 다음과 같이 특수 *, ?, + 등의 문자를 사용할 수도 있습니다. glob.glob('mydir/file[a-z]+')
2023.09.05 -
Study stuff for Golang
https://tour.golang.org/ http://golang.site/ https://nomadcoders.co/go-for-beginners Coding Convention https://golang.org/doc/effective_go https://dave.cheney.net/practical-go/presentations/qcon-china.html https://github.com/golang/go/wiki/CodeReviewComments Project Structure https://github.com/golang-standards/project-layout https://github.com/bxcodec/go-clean-arch https://github.com/katzien/go..
2023.07.24 -
Go test: table driven test with Parallel()
우리는 test driven test를 위해 Unit test 코드를 작성합니다. 이 때 하나의 unit test function을 여러가지 다양한 방식으로 test 하기 위해 여러 parameter들을 table로 만들어 사용합니다. 다음은 그 예입니다. func TestA(t *testing.T) { t.Parallel() testCases := []struct { name string value int }{ { name: "case 1", value: 1, }, { name: "case 2", value: 2, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // test code here t.Log(tc.value) ..
2023.06.22 -
Go gotcha examples
예를들어 다음과 같은 대표적인 'Go gotcha'들이 존재합니다. variable shadowing Go 에서는 inner scope에서 같은 이름으로 변수를 선언할 수 있습니다. 이는 이전의 변수에 접근할 수 없게 만드는 소위 'shadowing' 역할을 수행합니다. func main() { a := 1 fmt.Println(a) if true { a := 2 fmt.Println(a) } fmt.Println(a) } 위 코드의 출력은 다음과 같습니다. 1 2 1 slices and arrays Go에서 slice와 array는 매우 유사한 type 입니다. slices는 arrays에 대한 references이며 동적인 길이를 갖습니다. 반면에 arrays는 고정된 길..
2023.06.22