for example, I have a numpy array-like
import numpy as np
x=np.array([[1, 1, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0]])
當前輸出:ind=np.argwhere(x) #訪問的索引是按行的,是否可以按列訪問
required output:
[[0 0]
[4 0]
[0 1]
[3 1]
[2 2]
[1 3]
[2 3]
[3 3]
[0 4]
[1 5]
[2 6]
[4 6]
[3 8]]
uj5u.com熱心網友回復:
您可以轉置和交換列。
ind = np.argwhere(x.T)[:, [1, 0]]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/516045.html
標籤:Python麻木的
上一篇:np.multiply或pd.mul但使用什么乘法陣列取決于條件
下一篇:如何回圈遍歷計算機視覺輸出陣列
