Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

What is the meaning of string index out of range?

asked 8 years ago

Nilesh gravatar image

updated 8 years ago

FrédéricC gravatar image

I am dealing with [35,6] linear code over finite filed with 2 elements. I am able to get an output of its generator matrix as 6x35 matrix, but while computing parity check matrix which will be of size 29x35, I am getting following output: IndexError:string index out of range

Does it mean that its size is two large? If still it is so, how to get that matrix in sage??

Preview: (hide)

Comments

Could you please provide the full code that lead to the error ?

tmonteil gravatar imagetmonteil ( 8 years ago )

2 Answers

Sort by » oldest newest most voted
0

answered 8 years ago

tmonteil gravatar image

ithout further information on your concrete use case, such an error appears when you asks for the letter of a string at an index that is larger than the length of the string:

sage: s = 'abc'
sage: s[0]
'a'
sage: s[1]
'b'
sage: s[2]
'c'
sage: s[3]
IndexError: string index out of range
Preview: (hide)
link
0

answered 7 years ago

dan_fulea gravatar image

The following was working for me. A is a matrix of shape 6x35, taken (almost) randomly. (There was a rank check after getting it.) C is the linear code associated to it. B is the parity check matrix for the code.

sage: A = MatrixSpace( GF(2), 6, 35 ).random_element()
sage: A
[1 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0 1 1 1 1 1 0 0 1 1 1 0 1 1 0 1 1 1 0 1]
[1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1 1]
[1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 1 0 1 0 1 0 1 1 0 1]
[0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 0 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1]
[0 1 0 1 0 1 0 0 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 1 1]
[1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0]
sage: A.rank()
6
sage: # this is ok...
sage: C = LinearCode(A)
sage: B = C.parity_check_matrix()
sage: B
29 x 35 dense matrix over Finite Field of size 2 (use the '.str()' method to see the entries)
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 8 years ago

Seen: 637 times

Last updated: Mar 29 '17