file_out = open('./txt/'+out_txt_name, 'w') size=output_pred_mbbox.shape for i in range(0,size[0]): every_img = output_pred_mbbox[i,:,:,:] every_img_B = every_img[:,:,0] every_img_G = every_img[:,:,1] every_img_R = every_img[:,:,2] for s in range(every_img_B.shape[0]): for t in range(every_img_B.shape[1]): item = every_img_B[s,t] file_out.write(str(item)+' ') for s in range(every_img_G.shape[0]): for t in range(every_img_G.shape[1]): item = every_img_G[s,t] file_out.write(str(item)+' ') for s in range(every_img_R.shape[0]): for t in range(every_img_R.shape[1]): item = every_img_R[s,t] file_out.write(str(item)+' ') file_out.close()