write to a file two dict()

2012-09-23 Thread giuseppe . amatulli
Hi Have two dict() of the same length and i want print them to a common file. a={1: 1, 2: 2, 3: 3} b={1: 11, 2: 22, 3: 33} in order to obtain 1 1 1 11 2 2 2 22 3 3 3 33 I tried output = open(dst_file, "w") for (a), b , (c) , d in a.items() , b.items() : output.write("%i %i %i %i\n" % (

Re: looping in array vs looping in a dic

2012-09-20 Thread giuseppe . amatulli
Hi Ian and MRAB thanks to you input i have improve the speed of my code. Definitely reading in dic() is faster. I have one more question. In the dic() I calculate the sum of the values, but i want count also the number of observation, in order to calculate the average in the end. Should i creat

looping in array vs looping in a dic

2012-09-20 Thread giuseppe . amatulli
Hi, I have this script in python that i need to apply for very large arrays (arrays coming from satellite images). The script works grate but i would like to speed up the process. The larger computational time is in the for loop process. Is there is a way to improve that part? Should be better

Re: save dictionary to a file without brackets.

2012-08-09 Thread Giuseppe Amatulli
2007/idiomatic/handout.html#use-in-where-possible-1 >> >> That link doesn't actually discuss dict.{iter}items() >> >> Both are O(N) because you have to touch each item in the dict--you >> can't iterate over N entries in less than O(N) time. For small &

Re: save dictionary to a file without brackets.

2012-08-09 Thread Giuseppe Amatulli
deas? >> Thanks in advance > > How's this? > > from __future__ import print_function > > output = open("out.txt", "w") > > for (a, b), c in d.items(): > print(a, b, c, file=output) > > output.close() > > Oscar. >> -- >> http://mail.python.org/mailman/listinfo/python-list -- Giuseppe Amatulli Web: www.spatial-ecology.net -- http://mail.python.org/mailman/listinfo/python-list

Re: save dictionary to a file without brackets.

2012-08-09 Thread Giuseppe Amatulli
; > from __future__ import print_function > > output = open("out.txt", "w") > > for (a, b), c in d.items(): > print(a, b, c, file=output) > > output.close() > > Oscar. >> -- >> http://mail.python.org/mailman/listinfo/python-list -- Giuseppe Amatulli Web: www.spatial-ecology.net -- http://mail.python.org/mailman/listinfo/python-list

save dictionary to a file without brackets.

2012-08-09 Thread giuseppe . amatulli
Hi, I have a dict() unique like this {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? 4 5 1 5 4 1 4 4 2 2 3 1 4 3 2 Any ideas? Thanks in advance Giuseppe -- http://mail.python.o

Re: no data exclution and unique combination.

2012-08-09 Thread giuseppe . amatulli
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:

no data exclution and unique combination.

2012-07-24 Thread giuseppe . amatulli
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