본문 바로가기

공부기록/Python

Left-Right Flip Method 구현

입력값 array: np.array(), width: int, height: int

좌우 반전 메소드 구현

 

실행시간 전혀 고려안했음

start, end (좌표로 사용할 값) 구하는게 핵심인듯 이걸 왜 생각못했지

img = [0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0]
height, width = 4, 4
output_1 = []
output_2 = []

### 1. temp list
for h in range(height):
    start = h*width
    end = start+width
    temp = []

    for idx in range(end, start, -1): temp.append(img[idx-1])
    output_1.append(temp)


### 2. reverse (direct)
for h in range(height):
    start = h * width
    end = start + width

    output_2.append(img[start:end:][::-1])

print(output_1)
print(output_2)

 

하라할때는 못하다가 저녁에 차 마시면서 한가하게 하니까 10분도 안되어서 풀었다.

초조하면 패닉성향되는거도 있다지만, 이렇게 쉬운걸 못하다니 좀 충격받아서 알고리즘 공부 시작함..

'공부기록 > Python' 카테고리의 다른 글

[scikit-learn] F1 Score 산출  (0) 2023.04.16
[tkinter] 간단 예제  (0) 2018.10.09