MCPcopy Create free account
hub / github.com/numpy/numpy / einsum

Function einsum

numpy/core/einsumfunc.py:1010–1443  ·  view source on GitHub ↗

einsum(subscripts, *operands, out=None, dtype=None, order='K', casting='safe', optimize=False) Evaluates the Einstein summation convention on the operands. Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be r

(*operands, out=None, optimize=False, **kwargs)

Source from the content-addressed store, hash-verified

1008# Rewrite einsum to handle different cases
1009@array_function_dispatch(_einsum_dispatcher, module='numpy')
1010def einsum(*operands, out=None, optimize=False, **kwargs):
1011 """
1012 einsum(subscripts, *operands, out=None, dtype=None, order='K',
1013 casting='safe', optimize=False)
1014
1015 Evaluates the Einstein summation convention on the operands.
1016
1017 Using the Einstein summation convention, many common multi-dimensional,
1018 linear algebraic array operations can be represented in a simple fashion.
1019 In *implicit* mode `einsum` computes these values.
1020
1021 In *explicit* mode, `einsum` provides further flexibility to compute
1022 other array operations that might not be considered classical Einstein
1023 summation operations, by disabling, or forcing summation over specified
1024 subscript labels.
1025
1026 See the notes and examples for clarification.
1027
1028 Parameters
1029 ----------
1030 subscripts : str
1031 Specifies the subscripts for summation as comma separated list of
1032 subscript labels. An implicit (classical Einstein summation)
1033 calculation is performed unless the explicit indicator '->' is
1034 included as well as subscript labels of the precise output form.
1035 operands : list of array_like
1036 These are the arrays for the operation.
1037 out : ndarray, optional
1038 If provided, the calculation is done into this array.
1039 dtype : {data-type, None}, optional
1040 If provided, forces the calculation to use the data type specified.
1041 Note that you may have to also give a more liberal `casting`
1042 parameter to allow the conversions. Default is None.
1043 order : {'C', 'F', 'A', 'K'}, optional
1044 Controls the memory layout of the output. 'C' means it should
1045 be C contiguous. 'F' means it should be Fortran contiguous,
1046 'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise.
1047 'K' means it should be as close to the layout as the inputs as
1048 is possible, including arbitrarily permuted axes.
1049 Default is 'K'.
1050 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
1051 Controls what kind of data casting may occur. Setting this to
1052 'unsafe' is not recommended, as it can adversely affect accumulations.
1053
1054 * 'no' means the data types should not be cast at all.
1055 * 'equiv' means only byte-order changes are allowed.
1056 * 'safe' means only casts which can preserve values are allowed.
1057 * 'same_kind' means only safe casts or casts within a kind,
1058 like float64 to float32, are allowed.
1059 * 'unsafe' means any data conversions may be done.
1060
1061 Default is 'safe'.
1062 optimize : {False, True, 'greedy', 'optimal'}, optional
1063 Controls if intermediate optimization should occur. No optimization
1064 will occur if False and True will default to the 'greedy' algorithm.
1065 Also accepts an explicit contraction list from the ``np.einsum_path``
1066 function. See ``np.einsum_path`` for more details. Defaults to False.
1067

Callers

nothing calls this directly

Calls 8

tensordotFunction · 0.90
einsum_pathFunction · 0.85
asanyarrayFunction · 0.85
upperMethod · 0.80
replaceMethod · 0.80
findMethod · 0.80
allFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected