no data exclution and unique combination.
python at mrabarnett.plus.com
Tue Jul 24 21:08:38 CEST 2012
On 24/07/2012 19:51, MRAB wrote:
> On 24/07/2012 19:27, giuseppe.amatulli at gmail.com wrote:
>> would like to take eliminate a specific number in an array and its correspondent in an other array, and vice-versa.
>> after i need to calculate unique combination in pairs to count the observations
>> and obtain
>> For the fist task i did
>> a_No_data_a = a[a != no_data_a]
>> b_No_data_a = b[a != no_data_a]
>> b_clean = b_No_data_a[b_No_data_a != no_data_b]
>> a_clean = a_No_data_a[a_No_data_a != no_data_b]
>> but the results are not really stable.
> mask = (a != no_data_a) & (b != no_data_b)
> a_clean = a[mask]
> b_clean = b[mask]
>> For the second task
>> The np.unique would solve the problem if it can be apply to a two arrays.
I couldn't figure out how to do the second part in numpy, so:
from collections import Counter
counts = Counter(zip(a_clean, b_clean))
counts = [pair + (count,) for pair, count in counts.items()]
More information about the Python-list