Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

AttributeError: 'int' object has no attribute 'inverse_mod'

Hi i'm a beginner with Sage, and i have some trouble with types. It looks like the cause of my pain is trying to use numpy together with Sagemath, is it possible to use Sagemath without numpy?

here is a small example of an error that i encounter, when trying to do simple modular calculations in GF(7)

import numpy as np

a=[2,4,6,1,3,5]
b=[1,1,1,1,1,1]
p=7
n=len(a)
L=1
c=np.zeros(n,'int')
Li_ai=np.zeros(n)
for i in range(n):
    L=(x-a[i])*L
for i in range(n):
    Li=L/(x-a[i])
    t=(Li(x=a[i])%p)
    Li_ai[i]=t
Li_ai=Li_ai.astype('int')
tmp=Li_ai.prod()%p
Li_ai=vector(Li_ai)
for i in range(n):
    c[i]=tmp * (Li_ai[i]) * b[i].inverse_mod(p) %p
c=vector(c)
c
y=np.int(tmp)
y.inverse_mod(p)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_34.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("eS5pbnZlcnNlX21vZChwKQ=="),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/private/var/folders/gm/z065gk616xg6g0xgn4c7_bvc0000gn/T/tmpuCk1lu/___code___.py", line 2, in <module> exec compile(u'y.inverse_mod(p) File "", line 1, in <module> AttributeError: 'int' object has no attribute 'inverse_mod'

AttributeError: 'int' object has no attribute 'inverse_mod'

Hi i'm a beginner with Sage, and i have some trouble with types. It looks like the cause of my pain is trying to use numpy together with Sagemath, is it possible to use Sagemath without numpy?

here Here is a small example of an error that i encounter, when trying to do simple modular calculations in GF(7)GF(7).

I use the following code:

import numpy as np

a=[2,4,6,1,3,5]
b=[1,1,1,1,1,1]
p=7
n=len(a)
L=1
c=np.zeros(n,'int')
Li_ai=np.zeros(n)
for i in range(n):
    L=(x-a[i])*L
for i in range(n):
    Li=L/(x-a[i])
    t=(Li(x=a[i])%p)
    Li_ai[i]=t
Li_ai=Li_ai.astype('int')
tmp=Li_ai.prod()%p
Li_ai=vector(Li_ai)
for i in range(n):
    c[i]=tmp * (Li_ai[i]) * b[i].inverse_mod(p) %p
c=vector(c)
c
y=np.int(tmp)
y.inverse_mod(p)

and I get the following error:

Traceback (most recent call last): 
File "<stdin>", line 1, in <module>
File "_sage_input_34.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("eS5pbnZlcnNlX21vZChwKQ=="),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/private/var/folders/gm/z065gk616xg6g0xgn4c7_bvc0000gn/T/tmpuCk1lu/___code___.py", line 2, in <module> exec compile(u'y.inverse_mod(p) File "", line 1, in <module>
last) ... AttributeError: 'int' object has no attribute 'inverse_mod'

'inverse_mod'