Note

Numpy (50) 본문

Numpy

Numpy (50)

알 수 없는 사용자 2022. 9. 16. 14:00
728x90

How to convert an array of arrays into a flat 1d array?

 # Input:
arr1 = np.arange(3)
arr2 = np.arange(3,7)
arr3 = np.arange(7,10)

array_of_arrays = np.array([arr1, arr2, arr3])
print('array_of_arrays: ', array_of_arrays)

# Solution 1
arr_2d = np.array([a for arr in array_of_arrays for a in arr])

# Solution 2:
arr_2d = np.concatenate(array_of_arrays)
print(arr_2d)

# output
[0 1 2 3 4 5 6 7 8 9]

'Numpy' 카테고리의 다른 글

Numpy (52)  (0) 2022.09.20
Numpy (51)  (0) 2022.09.17
Numpy (49)  (0) 2022.09.15
Numpy (48)  (0) 2022.09.14
Numpy (47)  (0) 2022.09.13
Comments