Typeerror: 'int' Object Does Not Support Item Assignment Error
sig_txt: [45 67 83 32767 101 90 50] idx_rr:[101] // index after 32767 sig: [45 67 83 101 90 50] // all the elements except 32767 Basically what happens is from the original array,
Solution 1:
With idx_rr = i+1
the formerly defined list
becomes an int
so there's no index idx_rr[j]
to assign a value to. The same applies to the sig
variable.
Note that the problem is not the declaration, python allows you to re-assign a variable to a new type. The problem is that idx_rr
is of type int
and you cannot access and index idx_rr[j]
of an int
.
Try this
R_peak = False
j = 0
k = 0
idx_rr = []
idx_rr_int = 0
sig = []
sig_int = 0for i in range (len(sig_txt)):
if (sig_txt[i] == 32767):
idx_rr_int = i+1
idx_rr[j] = np.array(sig_txt[i+1])
sig_int = i+1
sig[k] = np.array(sig_txt[i+1])
k = k + 1
j = j + 1print(idx_rr_int)
R_peak = Trueelse:
if (R_peak == False):
sig_int = i
sig[k] = np.array(sig_txt[i])
k = k + 1else:
R_peak = False
plt.figure(figsize=(20,8))
plt.plot(sig)
plt.scatter([idx_rr], [sig[idx_rr]], c='g')
plt.show()
Solution 2:
After the line idx__rr = i+1
, you are changing the data type of idx_rr, which was list previously, to int.
Change the variable name of the list to get rid of the error.
Post a Comment for "Typeerror: 'int' Object Does Not Support Item Assignment Error"