Python Forum
Error: int object does not support item assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error: int object does not support item assignment
#1
Dear All,

I want to know how to remove this type of error. In this code i want to flip the values. But if I flip by giving 1D array index it flips and no error but if i have 2D List its not working and give this error. Please help me in this regard. What I have to change.

My part of code in error is below:
For example:one part of decoding process
add_attempt=4
LLR_L = signal.copy() * 2 / pow(sigma, 2)
LLR_L_ = LLR_L
    
indexes = np.argsort(np.abs(LLR_L))[:add_attempt]

comb =[]
    for i in indexes:
        comb.append(i)

COMB = []
    for L in range(0, len(comb) + 1):
        for subset in itertools.combinations(comb, L):
            COMB.append(subset)

   for i_flip in range(len(COMB)):
       L[:, n] = LLR_L_
           decoding process function here( if fails)
           else:
              LLR_L_ = LLR_L
              for j in range(len(COMB[i_flip])):
                  if LLR_L[COMB[i_flip][j]] > 0:
                     LLR_L_[COMB[i_flip][j]] = (-1) * 10
                  else:
                     LLR_L_[COMB[i_flip][j]] = 10
This code have an output I print just to know what is stored in these functions and error
Output:
indexes [ 3 14 5 22] comb [3, 14, 5, 22] COMB [(), (3,), (14,), (5,), (22,), (3, 14), (3, 5), (3, 22), (14, 5), (14, 22), (5, 22), (3, 14, 5), (3, 14, 22), (3, 5, 22), (14, 5, 22), (3, 14, 5, 22)]
error
Output:
Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\multiprocessing\pool.py", line 119, in worker result = (True, func(*args, **kwds)) File "C:\Users\ankita1268\Desktop\CRC-BP-Multi-G\main_Iter_mflip.py", line 120, in func polar_decoded_llr, a = polar_codes_iter_mflip.FG_decode(signal, polar_iter_num, stage_num, frozen_indexes, info_indexes, B_N, sigma, BIG_NUM, perm[perm_idx], alpha, beta, threshold, H_CRC,T) File "C:\Users\ankita1268\Desktop\CRC-BP-Multi-G\polar_codes_iter_mflip.py", line 203, in FG_decode L[:, n] = LLR_L_ TypeError: 'int' object does not support item assignment """ [color=#E74C3C] L[:, n] = LLR_L_ TypeError: 'int' object does not support item assignment[/color]
But this code runs if I have the last part of code as below:
   for i_flip in range(add_attempt):
      L[:, n] = LLR_L_
           decoding process function here( if fails)
           else:
           LLR_L_ = LLR_L
           if LLR_L[indexes[i_flip]] > 0:
               LLR_L_[indexes[i_flip]] = (-1) * 10
           else:
               LLR_L_[indexes[i_flip]] = 10
Reply
#2
As the error says, L is an integer. On line 12 you set it as an integer by using it as the loop variable in the for loop. Then on line 17 when you try to index it, you get the error. You can't index integers, only containers.

It's not clear what you expect L to be. It's not defined previously in the code you posted, but your error indicates there's a lot of code you didn't post. If you previously defined it to be something else, change the name of your loop variable on line 12.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
oh sorry ,

I did this silly mistake on line 12 ,

Thank you very much
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help with 'str' object is not callable error. Fare 4 825 Jul-23-2023, 02:25 PM
Last Post: Fare
  Error in Int object is not subscript-able. kakut 2 1,174 Jul-06-2022, 08:31 AM
Last Post: ibreeden
  Remove an item from a list contained in another item in python CompleteNewb 19 5,669 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,100 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
Star Type Error: 'in' object is not callable nman52 3 3,382 May-01-2021, 11:03 PM
Last Post: nman52
  Error in Int object is not subscript-able. How to debug this ? yanDvator 1 2,220 Aug-03-2020, 02:28 PM
Last Post: Larz60+
  Sympy error "object is not callable" Cupcake 0 4,889 Feb-08-2020, 02:22 AM
Last Post: Cupcake
  object is not subscriptable... Error Message? Shafla 3 11,833 Sep-25-2019, 12:27 AM
Last Post: buran
  'int' object does not support item assignment shane1236 5 7,518 Aug-13-2019, 01:53 PM
Last Post: buran
  Getting error "Type error-a bytes-like object..." mrapple2020 1 5,387 Apr-06-2019, 06:37 PM
Last Post: mrapple2020

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020