Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 标识一个numpy数组中产生另一个numpy数组的行_Arrays_Numpy - Fatal编程技术网

Arrays 标识一个numpy数组中产生另一个numpy数组的行

Arrays 标识一个numpy数组中产生另一个numpy数组的行,arrays,numpy,Arrays,Numpy,我想我遗漏了一些明显的东西。考虑下面的代码: import numpy as np a = np.array([[ 0, 2, 0, 5, 4, 6, 2, 4], [ 3, 4, 0, 1, 0, 7, 4, 6], [ 2, 6, 3, 5, 2, 5, 5, 8], [ 0, 1, 0, 8, 0, 5, 8, 10], [

我想我遗漏了一些明显的东西。考虑下面的代码:

import numpy as np

a = np.array([[ 0,  2,  0,  5,  4,  6,  2,  4],
              [ 3,  4,  0,  1,  0,  7,  4,  6],
              [ 2,  6,  3,  5,  2,  5,  5,  8],
              [ 0,  1,  0,  8,  0,  5,  8, 10],
              [ 7,  9,  2,  7,  0,  6,  7,  2],
              [ 0,  1,  4,  9,  0,  7,  9,  9],
              [ 0,  6,  7,  5,  6,  2,  4, 13],
              [ 0,  1,  1,  4,  1,  3,  2,  3]]


# isolate columns 2,3,6,7
mask = [False,False, True, True,False,False, True, True]             
b = a[:,mask]

# determine rows of b having unique elements
s = np.sort(b, axis=1)
c = b[~(s[:,:-1] == s[:,1:]).any(1)]
c
看起来像:

c = [[ 0,  5,  2,  4],
     [ 0,  1,  4,  6],
     [ 7,  5,  4, 13],
     [ 1,  4,  2,  3]]
问题:如何“恢复”产生
c
行的
a
行? 输出应如下所示:

d = [[ 0,  2,  0,  5,  4,  6,  2,  4],
     [ 3,  4,  0,  1,  0,  7,  4,  6],
     [ 0,  6,  7,  5,  6,  2,  4, 13],
     [ 0,  1,  1,  4,  1,  3,  2,  3]]

你可以不做a[~(s[:,:-1]==s[:,1:)。任何(1)]?当然谢谢。你可以不做a[~(s[:,:-1]==s[:,1:)。任何(1)]?当然谢谢。