例如:對于
A = np.array([
[1, 2, 3],
[4, 4, 4],
[5, 6, 6]])
我想得到輸出
array([[1, 2, 3]])。因為A = np.arange(9).reshape(3, 3),我想得到
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
不使用回圈
uj5u.com熱心網友回復:
您可以使用:
B = np.sort(A, axis=1)
out = A[(B[:,:-1] != B[:, 1:]).all(1)]
或使用熊貓:
import pandas as pd
out = A[pd.DataFrame(A).nunique(axis=1).eq(A.shape[1])]
輸出:
array([[1, 2, 3]])
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/519637.html
標籤:Python麻木的
