i got this error while trying to predict the machine learning model for single batch
but i do not know how to use any() or all() in my code i think because of the size of array at least
i have to use one of them any() or all()
Code:
saved_weights = find_checkpoint_file('.')
print('please enter the value')
user_input1 = input()
if len(saved_weights) == 0:
print("The network hasn't been trained! Program will exit...")
sys.exit()
else:
X_test = load_test_data(user_input1, X_word_to_ix, MAX_LEN)
print(type(X_test))
X_test = pad_sequences(X_test, maxlen=4, dtype='int32')
print(type(X_test))
model.load_weights(saved_weights)
predictions = np.array(model.predict(X_test))
print(type(predictions))
sequences = []
for prediction in predictions:
sequence = ' '.join([y_ix_to_word[index] for index in prediction if index > 0])
print(sequence)
l = sequences.append(sequence)
np.savetxt('test_result.txt', sequences, fmt='%s')
the line that i think though out the error:
sequence = ' '.join([y_ix_to_word[index] for index in prediction if index > 0])
error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
sequence = ' '.join([y_ix_to_word[index] for index in prediction if index > 0])
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
in the below image is the traceback of error traceback