Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26805
| From | giuseppe.amatulli@gmail.com |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: no data exclution and unique combination. |
| Date | 2012-08-09 13:06 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <bccc20ed-7570-4e15-980c-008987ce0361@googlegroups.com> (permalink) |
| References | <864b0104-daa8-4ea5-8003-6cfaab19fdea@googlegroups.com> |
Terry and MRAB,
thanks for yours suggestions,
in the end i found this solution
mask=( a != 0 ) & ( b != 0 )
a_mask=a[mask]
b_mask=b[mask]
array2D = np.array(zip(a_mask,b_mask))
unique=dict()
for row in array2D :
row = tuple(row)
if row in unique:
unique[row] += 1
else:
unique[row] = 1
print unique
{(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2}
I choose this solution because i could not install "from collections import Counter".
Anyway how i can print to a file the unique results without the brackets and obtain something like this?
4 5 1
5 4 1
4 4 2
2 3 1
4 3 2
Thanks in advance
Best regards.
Giuseppe
On Tuesday, 24 July 2012 13:27:05 UTC-5, giuseppe...@gmail.com 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])
>
>
>
> after i need to calculate unique combination in pairs to count the observations
>
> and obtain
>
> (4,3,2)
>
> (4,5,1)
>
> (5,4,1)
>
> (4,4,2)
>
>
>
> 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.
>
>
>
> For the second task
>
> The np.unique would solve the problem if it can be apply to a two arrays.
>
>
>
> Any idea?
>
> thanks in advance
>
> Giuseppe
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
no data exclution and unique combination. giuseppe.amatulli@gmail.com - 2012-07-24 11:27 -0700
Re: no data exclution and unique combination. MRAB <python@mrabarnett.plus.com> - 2012-07-24 19:51 +0100
Re: no data exclution and unique combination. MRAB <python@mrabarnett.plus.com> - 2012-07-24 20:08 +0100
Re: no data exclution and unique combination. Terry Reedy <tjreedy@udel.edu> - 2012-07-24 15:32 -0400
Re: no data exclution and unique combination. giuseppe.amatulli@gmail.com - 2012-08-09 13:06 -0700
Re: no data exclution and unique combination. Dave Angel <d@davea.name> - 2012-08-09 17:23 -0400
Re: no data exclution and unique combination. Terry Reedy <tjreedy@udel.edu> - 2012-08-09 17:33 -0400
Re: no data exclution and unique combination. Hans Mulder <hansmu@xs4all.nl> - 2012-08-10 10:47 +0200
csiph-web