I will like mask 10 values in the middle of array and mix with 10 max and 10 min values.
我想在数组中间屏蔽10个值,并混合10个最大值和10个最小值。
Create array
创建数组
z = np.random.random((10,10))
Sorted
排序
sorted = np.sort(z,axis=None)
logical premise 10 max and 10 min
逻辑前提10最大和10分钟
p=np.logical_and(z >= sorted[10], z <= sorted[-10])
Execute premise
执行前提
c = ma.masked_where(p, z, copy=True)
go to the center
去中心
pos_1=len(sorted)/2-5
pos_2=len(sorted)/2+5
logical premise 10 values in the middle:
逻辑前提中间10个值:
p=np.logical_or(z < float(sorted[pos_1]) , z > float(sorted[pos_2]))
Execute premise
执行前提
c = ma.masked_where(p, z, copy=True)
THE LAST IS WORKING ALSO I DONT KNOW HOW CAN JOIN THE TWO RESULTS. I REFER THE MASK OF THE TWO RESULTS
最后工作,我不知道如何加入这两个结果。我推荐两个结果的面具
If you could help me.
如果你能帮帮我
1 个解决方案
#1
1
OK I fint the solution, I think is heavy and any person could find one better
好吧,我提出解决方案,我认为很重,任何人都可以找到更好的解决方案
z = np.random.random((10,10))
p=np.logical_and(z >= sorted[10], z <= sorted[-10])
a = ma.masked_where(p, z, copy=True)
p=np.logical_or(z < float(sorted[pos_1]) , z > float(sorted[pos_2]))
b = ma.masked_where(p, z, copy=True)
The problem that I fix, combine the two mask, but you need invert first, because I realease with a OR operation.
我修复的问题,结合两个掩码,但你需要先反转,因为我使用OR操作重新发布。
c =np.ma.mask_or(~a.mask, ~b.mask)
and result
和结果
print np.ma.masked_array(z,~c)
#1
1
OK I fint the solution, I think is heavy and any person could find one better
好吧,我提出解决方案,我认为很重,任何人都可以找到更好的解决方案
z = np.random.random((10,10))
p=np.logical_and(z >= sorted[10], z <= sorted[-10])
a = ma.masked_where(p, z, copy=True)
p=np.logical_or(z < float(sorted[pos_1]) , z > float(sorted[pos_2]))
b = ma.masked_where(p, z, copy=True)
The problem that I fix, combine the two mask, but you need invert first, because I realease with a OR operation.
我修复的问题,结合两个掩码,但你需要先反转,因为我使用OR操作重新发布。
c =np.ma.mask_or(~a.mask, ~b.mask)
and result
和结果
print np.ma.masked_array(z,~c)