在3的numpy矩阵中查找匹配的行

时间:2020-04-24 03:54:20

标签: python-3.x numpy cube

给定一个mxmxm多维数据集,我需要知道6个面上的行,这些行中的最小值大于给定的n。

2 个答案:

答案 0 :(得分:-1)

获取各种面孔:

faces = np.array([
    x[ 0,  :,  :],
    x[-1,  :,  :],
    x[ :,  0,  :],
    x[ :, -1,  :],
    x[ :,  :,  0],
    x[ :,  :, -1],
])

现在折叠最后一个尺寸轴:

# No information on orientation provided by OP so always pick axis=-1
row_mins = np.min(faces, axis=-1)

然后仅保留满足条件的行:

valid_rows = faces[row_mins > n]
print(valid_rows)

答案 1 :(得分:-1)

您可以在迭代的帮助下过滤值。对于numpy iteration

code_image

代码

import numpy as np
data=np.arange(54).reshape(6,3,3)
print(data,data.ndim)

#n : given value to filter
n=10

#to get all the elements that are greater than n
print(data[data>n])

for i in data:
  for row in i:
    if  row[row>n].size :
        print(row)

如果您有任何疑问,请告诉我。