Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Problem description

Agree to Privacy Statement

mindspore.scipy.optimize.linear_sum_assignment

View Source On Gitee
mindspore.scipy.optimize.linear_sum_assignment(cost_matrix, maximize, dimension_limit=Tensor(sys.maxsize))[source]

Solve the linear sum assignment problem.

The assignment problem is represented as follows:

minijCi,jXi,j

where C is cost matrix, Xi,j=1 means column j is assigned to row i .

Parameters
  • cost_matrix (Tensor) – 2-D cost matrix. Tensor of shape (M,N) .

  • maximize (bool) – Calculate a maximum weight matching if true, otherwise calculate a minimum weight matching.

  • dimension_limit (Tensor, optional) – A scalar used to limit the actual size of the 2nd dimension of cost_matrix. Default is Tensor(sys.maxsize), which means no limitation. The type is 0-D int64 Tensor.

Returns

A tuple of tensors containing 'row_idx' and 'col_idx'.

  • row_idx (Tensor) - Row indices of the problem. If dimension_limit is given, -1 would be padded at the end. The shape is (N,) , where N is the minimum value of cost_matrix dimension.

  • col_idx (Tensor) - Column indices of the problem. If dimension_limit is given, -1 would be padded at the end. The shape is (N,) , where N is the minimum value of cost_matrix dimension.

Raises
  • TypeError – If the data type of cost_matrix is not the type in [float16, float32, float64, int8, int16, int32, int64, uint8, uint16, uint32, uint64, bool]

  • TypeError – If the type of maximize is not bool.

  • TypeError – If the data type of dimension_limit is not int64.

  • ValueError – If the rank of cost_matrix is not 2.

Supported Platforms:

Ascend CPU

Examples

>>> import mindspore as ms
>>> import numpy as np
>>> from mindspore import Tensor
>>> import mindspore.scipy.optimize.linear_sum_assignment as lsap
>>> cost_matrix = Tensor(np.array([[2, 3, 3], [3, 2, 3], [3, 3, 2]])).astype(ms.float64)
>>> dimension_limit = Tensor(2)
>>> maximize = False
>>> a, b = lsap(cost_matrix, maximize, dimension_limit)
>>> print(a)
[0 1 -1]
>>> print(b)
[0 1 -1]
>>> a, b = lsap(cost_matrix, maximize)
>>> print(a)
[0 1 2]
>>> print(b)
[0 1 2]