
tjreedy at udel
Jul 24, 2012, 12:32 PM
Post #5 of 9
(226 views)
Permalink
|
|
Re: no data exclution and unique combination.
[In reply to]
|
|
On 7/24/2012 2:27 PM, giuseppe.amatulli [at] gmail wrote: > Hi, > would like to take eliminate a specific number in an array and its correspondent in an other array, and vice-versa. > > given > > a=np.array([1,2,4,4,5,4,1,4,1,1,2,4]) > b=np.array([1,2,3,5,4,4,1,3,2,1,3,4]) > > no_data_a=1 > no_data_b=2 > > a_clean=array([4,4,5,4,4,4]) > b_clean=array([3,5,4,4,3,4]) As I discovered when running the solution before, your test data are wrong, leaving out 2,3 before the last pair (4,4). Anyway, for those interested in a plain Python solution, without numpy: a=[1,2,4,4,5,4,1,4,1,1,2,4] b=[1,2,3,5,4,4,1,3,2,1,3,4] no_data_a=1 no_data_b=2 a_clean=(4,4,5,4,4,2,4) b_clean=(3,5,4,4,3,3,4) cleaned = list(zip(*(pair for pair in zip(a,b) if pair[0] != no_data_a and pair[1] != no_data_b))) print(cleaned, cleaned == [a_clean, b_clean]) # [.(4, 4, 5, 4, 4, 2, 4), (3, 5, 4, 4, 3, 3, 4)] True -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
|