[diary #4] Numpy Iterator(order elements)

kamchur·2022년 10월 14일
0

😁START

numpy iterator can extract in order elements of matrix in list


arr = np.array([[11, 22, 33], [44, 55, 66], [77, 88, 99]])
arr
[result]
array([[11, 22, 33],
       [44, 55, 66],
       [77, 88, 99]])

iterator code

iterator = np.nditer(arr, flags=['multi_index'])

while not iterator.finished:
    value = iterator.multi_index
    
    print(value, end=' ')
    print(arr[value])
    
    iterator.iternext()
[result]
(0, 0) 11
(0, 1) 22
(0, 2) 33
(1, 0) 44
(1, 1) 55
(1, 2) 66
(2, 0) 77
(2, 1) 88
(2, 2) 99

😂END

2022.10.14. first commit
profile
chase free

0개의 댓글