我希望numpy通过第1列并找到大于0的所有数字....然后我想要numpy打印出column1它找到的所有正数和column2这个数字与第1列相关联的数字。
import numpy
N = 3
a1 = [-0.0119,0.0754,0.0272,0.0107,-0.0053,-0.0114,0.0148,0.0062,0.0043,0,0.022,-0.0153,0.0207,-0.0065,0.0069,-0.0018,0.0149,-0.0084,-0.0021,0.0072,0.0095,0.0004,0.0068,0.0016,-0.0048,0.0051,0.0025,0.0081,-0.0203,-0.0008,-0.0008,-0.0047,-0.0007,-0.0291,0.0071,0.0033,0.0179,-0.0016,0.0397,0.0075,0.0061,-0.0075,0.0026,-0.0055,-0.006,0.0026,-0.0046,0.0046,0.0201,0.023,0.0014,-0.0029,0.0115,0.0066,0.0071,0.0061,-0.0081,-0.0071,0.0005,-0.0076,0.0102,-0.0051,0.018,0.0017,0.0123,0.0021,-0.0032,0.0049,0.0004,0.0053,-0.0004,0.0138,-0.0215,0.0019,0.0023,-0.0059,-0.013,-0.0478,-0.0009,0.0089,0.0006,0.014,-0.0077,0.0006,0.0024,0.0113,0.0062,-0.0162,0.0198,0.0096,0.0167,-0.0018,0.0038,0.0088,0.0023,-0.0063,-0.0109,0.0127,-0.027,0,0.0089,-0.0003,0.023,-0.0009,0.02,-0.0059,0.0029,0.0219,-0.0003,0.0029,0.0072,-0.009,0.0025,0.0123,0.0106,-0.0024,-0.0267,0.0124,0.0012,0.0046,-0.0131,0.0133,-0.0075,0.009,0.0209,0.0106,0.0031,0.0019,-0.0122,0.002,-0.0261,-0.004,0.4034]
a1= a1[::-1]
a1 = numpy.array(a1)
numbers_mean = numpy.convolve(a1, numpy.ones((N,))/N)[(N-1):]
numbers_mean = numbers_mean[::-1]
numbers_mean = numbers_mean.reshape(-1,1)
a1 = a1.reshape(-1,1)
x = numpy.column_stack((a1,numbers_mean))
l = x[0<a1]
当我打印l时,我得到的是column1的结果我还想要在column2中显示的数字(column2未被过滤)
答案 0 :(得分:1)
这是解决方法如何按列1排序并带来所有列。
xx = x[x[:,0]>0,:]