I am running the python code and facing that error. I am trying to resolve it but I couldn't because I am not familiar with python. So, guide me and suggest a proper solution. I want to calculate the Dissimilarity Score from two Results respectively with and without GAN. Here is the part of the code which has an issue:
raw_seq = class_instances[:,1]
n_steps = len(class_instances1[:,1])
X, y = split_sequence(raw_seq, n_steps)
n_features = 1
X = X.reshape((X.shape[0], X.shape[1], n_features))
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=(n_steps, n_features)))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
model.fit(X, y, epochs=200, verbose=0)
model.summary()
x_input = class_instances1[:,1]
x_input = numpy.array(n_steps[6:13])
x_input = x_input.reshape((1, n_steps, n_features))
yhat = model.predict(x_input, verbose=0)
print("\n Result:", yhat, "\n")
This is the output:
Mean Feature Representation (MFR) : 74.47619047619048
Difference of each activity with MFR:
[42.47619047619048, 40.47619047619048, -120.52380952380952, -39.52380952380952, -185.52380952380952, 51.47619047619048, 24.47619047619048, 50.47619047619048, -69.52380952380952, 54.47619047619048, 9.476190476190482, 64.47619047619048, -25.52380952380952, 54.47619047619048, 53.47619047619048, -71.52380952380952, 33.47619047619048, 23.47619047619048, 57.47619047619048, -2.5238095238095184, -45.52380952380952]
Model: "sequential_10"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_10 (LSTM) (None, 50) 10400
_________________________________________________________________
dense_10 (Dense) (None, 1) 51
=================================================================
Total params: 10,451
Trainable params: 10,451
Non-trainable params: 0
_________________________________________________________________
Traceback (most recent call last):
File "C:\Users\Lenovo\anaconda3\thesis code\TC_code.py", line 102, in <module>
x_input = numpy.array(n_steps[6:13])
TypeError: 'int' object is not subscriptable
In python, you may use indices only on iterable objects (eg, lists
, numpy.arrays
etc.). As the error states, in the following line:
x_input = numpy.array(n_steps[6:13])
you try to index n_steps
variable, which is an int
and comes from n_steps = len(class_instances1[:,1])
, which is not permitted.
Cheers
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.