M
mensanator
## Holy Mother of Pearl!
##
## >>> for i in range(10):
## for j in range(10):
## print '%4d' % (gmpy.mpz(i)*gmpy.mpz(j)),
## print
##
##
## 0 0 0 0 0 0 0 0 0 0
## 0 1 2 3 1 5 6 7 2 9
## 0 2 4 6 2 10 12 14 4 18
## 0 3 6 9 3 15 18 21 6 27
## 0 1 2 3 1 5 6 7 2 9
## 0 5 10 15 5 25 30 35 10 45
## 0 6 12 18 6 30 36 42 12 54
## 0 7 14 21 7 35 42 49 14 63
## 0 2 4 6 2 10 12 14 4 18
## 0 9 18 27 9 45 54 63 18 81
No wonder I couldn't figure out why my program wasn't working,
gmpy mutiplication seems to have stopped working.
My guess is that when I did
import gmpy
import random
import operator
I somehow messed up gmpy's mutilpication. I brought in operator
because I needed to do
NN = sum(map(operator.__mul__,X,C))
which seemed to work ok. It was later when I got
8 * 3 = 6 (the 3 was an mpz)
that I got in trouble. So I got rid of operator and did
def product(a,b): return a*b
NN = sum(map(product,X,C))
which seems to work ok.
Am I correct that there is a conflict with
import gmpy
import operator
Would reversing the import order help or should I just avoid
mixing them?
##
## >>> for i in range(10):
## for j in range(10):
## print '%4d' % (gmpy.mpz(i)*gmpy.mpz(j)),
##
##
## 0 0 0 0 0 0 0 0 0 0
## 0 1 2 3 1 5 6 7 2 9
## 0 2 4 6 2 10 12 14 4 18
## 0 3 6 9 3 15 18 21 6 27
## 0 1 2 3 1 5 6 7 2 9
## 0 5 10 15 5 25 30 35 10 45
## 0 6 12 18 6 30 36 42 12 54
## 0 7 14 21 7 35 42 49 14 63
## 0 2 4 6 2 10 12 14 4 18
## 0 9 18 27 9 45 54 63 18 81
No wonder I couldn't figure out why my program wasn't working,
gmpy mutiplication seems to have stopped working.
My guess is that when I did
import gmpy
import random
import operator
I somehow messed up gmpy's mutilpication. I brought in operator
because I needed to do
NN = sum(map(operator.__mul__,X,C))
which seemed to work ok. It was later when I got
8 * 3 = 6 (the 3 was an mpz)
that I got in trouble. So I got rid of operator and did
def product(a,b): return a*b
NN = sum(map(product,X,C))
which seems to work ok.
Am I correct that there is a conflict with
import gmpy
import operator
Would reversing the import order help or should I just avoid
mixing them?