Created
August 5, 2021 05:17
-
-
Save Keiku/9fa4a944128990d931f5ff1592af7723 to your computer and use it in GitHub Desktop.
Get the index that meets the conditions from the 2d array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# sample array | |
array = np.array([[1, 1, 1, 0, 0, 0], | |
[1, 1, 1, 0, 0, 0]]) | |
# get row index and col index | |
rows, cols = np.where(array == 1) | |
# Convert row index and column index to 2d array | |
np.transpose((rows, cols)) | |
# array([[0, 0], | |
# [0, 1], | |
# [0, 2], | |
# [1, 0], | |
# [1, 1], | |
# [1, 2]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment