I'm really sorry to bother you with an AttributeError, but I just can't figure out what's wrong with my code.
My goal is to be able to access the C matrix's elements through certain functions I have not listed here. But for that to happen I figured I'd have to convert the matrix to a string.
from sage.all import *
import numpy as np
import random
import sage.all
def __NewTable__(C):
A=np.array_str(C)
word=""
MS=[]
for letter in A:
if letter==')':
word=''.join(letter)
MS.append(word)
word=""
else:
word=''.join(letter)
return MS
length=int(raw_input("Give length of linear code"))
dimention=int(raw_input("Give the dimention"))
FF=int(raw_input("Give the finite field in which you want to work in"))
C = codes.ReedSolomonCode(length, dimention, GF(FF, "x"))
MS=__NewTable__(C)
print MS
I get the following error after giving the arguments (length, dimention, FF)
AttributeError: 'LinearCode_with_category' object has no attribute 'shape'
The AttributeError
exception is raised when evaluating np.array_str(C)
.
Indeed, np.array_str
is a function to convert a numpy array into a string, so np.array_str(C)
starts by trying to figure out the shape of its argument C
(expected to be a numpy array), but in your use case C
is not a numpy array and has no shape
.
One workaround would be to write
A = np.array_str(np.array(C.list()))
or you might get rid of numpy and just use
A = str(C.list())
and then you don't need to import numpy.
Tips to get better help:
raw_input
)In summary, starting SageMath and defining __NewTable__
as follows:
def __NewTable__(C):
A = str(C.list())
word = ""
MS = []
for letter in A:
if letter == ')':
word = ''.join(letter)
MS.append(word)
word = ""
else:
word = ''.join(letter)
return MS
here is how that function would work:
sage: C = codes.ReedSolomonCode(4, 3, GF(5, "x"))
sage: MS = __NewTable__(C)
sage: print MS
[')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')']
Not sure that's really what you want, but at least the AttributeError
is gone and you can take it from here. Don't hesitate to let us know how this works out.