EADST

Maximize Sum with Unique Row and Column Numbers

Maximize the sum of the table where each number must come from the unique row and column. Maximum cost bipartite matching problem can be solved with the Hungarian algorithm.

from scipy.optimize import linear_sum_assignment
import numpy as np

cost =np.array(
    [
        [12,7,9,7,9],
        [8,9,6,6,6],
        [7,17,12,14,9],
        [15,14,6,6,10],
        [4,10,7,10,9]
    ])
row_ind, col_ind=linear_sum_assignment(cost)
res = np.zeros_like(cost) # np.ones_like
res[row_ind, col_ind] = 1
print(res)                          
#[[0 1 0 0 0]
# [0 0 1 0 0]
#[0 0 0 0 1]
#[0 0 0 1 0]
#[1 0 0 0 0]]
print(cost[row_ind,col_ind].sum())  # 32 total cost

Reference

StackOverflow

指派问题 —— 匈牙利算法

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
CUDA 多进程 logger Magnet WAN ONNX Paddle Bin Breakpoint Use Interview Excel Qwen2.5 公式 Clash CLAP HaggingFace CAM GPT4 CV Pillow diffusers 强化学习 RGB NameSilo Firewall Safetensors SQL Ubuntu Git CTC Web Plate Baidu Freesound Template Base64 PDF Statistics mmap YOLO Hungarian UNIX 图形思考法 TensorFlow Agent Nginx 阿里云 证件照 Bitcoin BTC Windows CEIR scipy Claude TensorRT FastAPI Gemma Translation News FP64 GPTQ v0.dev PyTorch GoogLeNet Hotel Google Streamlit Paper Password InvalidArgumentError 关于博主 Markdown 算法题 Input LoRA Pickle Crawler 云服务器 飞书 Permission ResNet-50 transformers Proxy Domain COCO Disk 第一性原理 Algorithm 多线程 Qwen Knowledge 腾讯云 OpenCV LLAMA SAM Math Tracking tqdm Django FP8 CC RAR Python DeepSeek PyCharm BF16 torchinfo Website 版权 git-lfs Video Vim FlashAttention EXCEL FP16 Tensor Bert Distillation 域名 Pytorch Tiktoken Sklearn C++ PIP 继承 SQLite Animate JSON HuggingFace Jupyter 搞笑 Numpy Datetime VPN uWSGI GIT ChatGPT Data Augmentation Plotly Review Dataset SPIE Transformers AI 顶会 API 签证 Jetson v2ray Ptyhon Color git VGG-16 Linux printf Llama Quantization LeetCode Qwen2 TTS IndexTTS2 Diagram Conda Cloudreve Quantize Github GGML Logo WebCrawler Miniforge QWEN XGBoost OpenAI Bipartite NLTK ModelScope hf Heatmap Attention TSV PDB OCR LLM LaTeX MD5 Docker VSCode Shortcut 财报 递归学习法 音频 Search Vmess 净利润 UI Food Zip llama.cpp Michelin 报税 CSV Random Anaconda FP32 uwsgi Image2Text Land XML SVR BeautifulSoup NLP DeepStream tar Pandas Hilton Card Mixtral
站点统计

本站现有博文321篇,共被浏览764724

本站已经建立2442天!

热门文章
文章归档
回到顶部