Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.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
Python 有效地减少一个大的np数组_Python_Arrays_Numpy - Fatal编程技术网

Python 有效地减少一个大的np数组

Python 有效地减少一个大的np数组,python,arrays,numpy,Python,Arrays,Numpy,我需要减少以下类型的非零数组: a = np.zeros([10**4,10**4]) a[column_index].sum() > threshold 以满足以下类型的简单约束条件的较小数量的标注(列): a = np.zeros([10**4,10**4]) a[column_index].sum() > threshold 我可以通过迭代和调用.delete轻松地完成这项工作,但实际上我正在寻找更有效的方法(因为数组非常大)。有任何提示吗?沿轴0求和以获得所有列的总和

我需要减少以下类型的非零数组:

a = np.zeros([10**4,10**4])
a[column_index].sum() > threshold
以满足以下类型的简单约束条件的较小数量的标注(列):

a = np.zeros([10**4,10**4])
a[column_index].sum() > threshold

我可以通过迭代和调用.delete轻松地完成这项工作,但实际上我正在寻找更有效的方法(因为数组非常大)。有任何提示吗?

沿轴0求和以获得所有列的总和,然后创建布尔数组以选择列:

import numpy as np

a = np.random.randint(0, 100, [100,100])
b = a[:, a.sum(axis=0) > 5000]
print b.sum(axis=0)
输出:

array([5359, 5045, 5116, 5512, 5143, 5261, 5209, 5018, 5009, 5025, 5353,
       5149, 5407, 5258, 5148, 5527, 5176, 5173, 5028, 5110, 5406, 5211,
       5287, 5163, 5364, 5623, 5257, 5361, 5528, 5049, 5298, 5280, 5201,
       5099, 5314, 5071, 5318, 5076, 5005, 5032, 5194, 5411, 5329, 5293])

沿轴0求和以获得所有列之和,然后创建布尔数组以选择列:

import numpy as np

a = np.random.randint(0, 100, [100,100])
b = a[:, a.sum(axis=0) > 5000]
print b.sum(axis=0)
输出:

array([5359, 5045, 5116, 5512, 5143, 5261, 5209, 5018, 5009, 5025, 5353,
       5149, 5407, 5258, 5148, 5527, 5176, 5173, 5028, 5110, 5406, 5211,
       5287, 5163, 5364, 5623, 5257, 5361, 5528, 5049, 5298, 5280, 5201,
       5099, 5314, 5071, 5318, 5076, 5005, 5032, 5194, 5411, 5329, 5293])

说清楚点,你说的“更少的维度数”是指“更少的行”?说清楚点,你说的“更少的维度数”是指“更少的行”?真不错,我正想找一个这种过滤的例子。干得好。真的很好,我正在寻找这种过滤的例子。干得好