def outputTxt(
                modelOutput, 
                target, 
                answerArray, 
                answerFilename, 
                truthFilename, 
                topK=1, 
                outputProb=False):
    with open(truthFilename, 'w+') as f:
        for n in range(0, target.shape[0]):
            f.write(answerArray[target[n, 0]] + '\n')
    with open(answerFilename, 'w+') as f:
        for n in range(0, modelOutput.shape[0]):
            if topK == 1:
                f.write(answerArray[np.argmax(modelOutput[n, :])])
                if outputProb:
                    f.write(',%.4f' % modelOutput[n, np.argmax(modelOutput[n, :])])
                f.write('\n')
            else:
                sortIdx = np.argsort(modelOutput[n], axis=0)
                sortIdx = sortIdx[::-1]
                for i in range(0, topK):
                    f.write(answerArray[sortIdx[i]])
                    if outputProb:
                        f.write(',%.4f' % modelOutput[n, sortIdx[i]])
                    f.write('\n')
Output the results of all examples into a text file.
dataset/ETHPy150Open renmengye/imageqa-public/src/imageqa_test.py/outputTxt