Python返回数组不为0位置,并组合起来

import numpy as np
C = np.arange(15).reshape(3, 5)
choice = np.where(C!=0)
print(choice)
#(array([0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2], dtype=int64), array([1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4], dtype=int64))
print(*choice)
#[0 0 0 0 1 1 1 1 1 2 2 2 2 2] [1 2 3 4 0 1 2 3 4 0 1 2 3 4]
list1=list(map(list, zip(*choice)))
print(list1)
#[[0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4]]

你可能感兴趣的:(python,image)