I want to add two arrays, follow_dismiss
and display
that have only one value:
follow_dismiss
[(408L,), (14L,), (59L,), (6L,), (32L,), (62L,), (59L,), (120L,), (53L,), (150L,), (3L,), (1L,), (60L,), (1L,), (126L,), (41L,), (239L,), (163L,), (11L,), (42L,), (1L,), (2L,), (5L,), (1L,), (2L,), (4L,)]
display
[(382L,), (6L,), (295L,), (1L,), (8L,), (33L,), (30L,), (24L,), (5L,), (233L,), (1L,), (65L,), (21L,), (20L,), (86L,), (171L,), (2L,), (29L,), (2L,), (3L,), (1L,)]
They come from SQL queries, for example:
cur.execute("""-- nombre de fois ou l'on propose une pub a l'utilisateur par utilisateur
SELECT COUNT (swipe.state) FROM swipe
WHERE swipe.state= 1 OR swipe.state = 4 or swipe.state=7
GROUP BY swipe.subscriber_id
ORDER BY swipe.subscriber_id;""")
display = cur.fetchall()
To get:
[790, 20, 9, ...]
Another example:
[(1,2), (3, 4)] + [(2, 3), (1, 3)] = [(3,5), (4, 7)]
Not even that works:
SUM_follow_dismiss_display_i = [x + y for x, y in zip(follow_dismiss, display)]
Because it gives:
[(408L, 381L), (14L, 6L), (59L, 294L), (6L, 1L), (32L, 8L), (62L, 33L), (59L, 30L), (120L, 24L), (53L, 5L), (150L, 233L), (3L, 1L), (1L, 65L), (60L, 21L), (1L, 20L), (126L, 86L), (41L, 171L), (239L, 2L), (163L, 29L), (11L, 2L), (42L, 3L), (1L, 1L)]
Not even that:
SUM_follow_dismiss_display_i = map(add,follow_dismiss,display)
What it gives:
SUM_follow_dismiss_display_i = map(add,follow_dismiss,display)
TypeError: can only concatenate tuple (not "NoneType") to tuple
He did it because I want to divide each square with its equivalent of the other array in a last array, result matrix. Without emargo map (truediv, arry1, arry2) it does not work because it tells me that:
print follow_dismiss
print SUM_follow_dismiss_display_i
m_i = map(truediv, SUM_follow_dismiss, SUM_follow_dismiss_display_i)
[(408L,), (14L,), (59L,), (6L,), (32L,), (62L,), (59L,), (120L,), (53L,), (150L,), (3L,), (1L,), (60L,), (1L,), (126L,), (41L,), (239L,), (163L,), (11L,), (42L,), (1L,), (2L,), (5L,), (1L,), (2L,), (4L,)]
[(408L, 381L), (14L, 6L), (59L, 294L), (6L, 1L), (32L, 8L), (62L, 33L), (59L, 30L), (120L, 24L), (53L, 5L), (150L, 233L), (3L, 1L), (1L, 65L), (60L, 21L), (1L, 20L), (126L, 86L), (41L, 171L), (239L, 2L), (163L, 29L), (11L, 2L), (42L, 3L), (1L, 1L)]
Traceback (most recent call last):
File "./testPostreSQLPython.py", line 72, in <module>
m_i = map(truediv, SUM_follow_dismiss, SUM_follow_dismiss_display_i)
TypeError: argument 2 to map() must support iteration