HackerRank 문제: https://www.hackerrank.com/challenges/np-concatenate/problem
import numpy as np
first = input().split(' ')
rows1, rows2= int(first[0]), int(first[1])
data1 = []
for _ in range(rows1):
next = input().split(' ')
data1.append([int(x) for x in next])
data1 = np.array(data1)
data2 = []
for _ in range(rows2):
next = input().split(' ')
data2.append([int(x) for x in next])
data2 = np.array(data2)
print(np.concatenate((data1, data2)))
import numpy as np
first = input().split(' ')
rows, columns = int(first[0]) + int(first[1]), int(first[2])
data = []
for _ in range(rows):
next = input().split(' ')
data.append([int(x) for x in next])
result = np.array(data)
print(result)
→ .concatenate() 안쓰고
① numpy.concatenate(array name, axis=0, out=None)
axis parameter에 넣은 값대로 배열을 합쳐준다.
axis에 None을 넣으면 flatten된다. 디폴트 값은 0.
예시)
>>> array1 = np.array([[1, 2], [3, 4]])
>>> array2 = np.array([[5, 6], [7, 8]])
>>> print(np.concatenate((array1, array2), axis=None))
# [1 2 3 4 5 6 7 8]
'Computer Science > [20-4] Numpy 연습' 카테고리의 다른 글
[Numpy] (6) Array Mathematics (0) | 2020.04.03 |
---|---|
[Numpy] (5) Eye and Identity (0) | 2020.04.02 |
[Numpy] (4) Zeros and Ones (0) | 2020.04.01 |
[Numpy] (2) Transpose and Flatten, flatten()과 ravel()의 차이점 (0) | 2020.03.30 |
[Numpy] (1) Numpy arrays basic (0) | 2020.03.29 |
댓글