Colorful Wires

エンジニアリングの勉強の記録

einsum の使い方

numpy.einsum の使い方を学ぶべく、マニュアルを翻訳する。まだ未完成。

以下に numpy.einsumシグネチャを記載します。

einsum(*operands, out=None, optimize=False, **kwargs)
    einsum(subscripts, *operands, out=None, dtype=None, order='K',
           casting='safe', optimize=False)

Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be represented in a simple fashion.

アインシュタインの縮約表記を使うことで、 複数の共通する多次元の線形代数配列の演算をシンプルに表現することができます。

In implicit mode einsum computes these values.

implicit モードでは einsum は以下の値を計算します。

In explicit mode, einsum provides further flexibility to compute other array operations that might not be considered classical Einstein summation operations, by disabling, or forcing summation over specified subscript labels.

explicit モードでは、einsum は 指定した添え字に対する総和を無効にしたり強制することにより、 古典的なアインシュタイン縮約表記の範疇から外れる ほかの配列演算に対するさらなる柔軟性を提供します。

See the notes and examples for clarification.

明確化のためのノートと例を参照してください。

Parameters

パラメーター

subscripts : str

添え字: str

Specifies the subscripts for summation as comma separated list of subscript labels. An implicit (classical Einstein summation) calculation is performed unless the explicit indicator '->' is included as well as subscript labels of the precise output form.

カンマでセパレートされた添え字ラベルのリストを指定します。 正確な出力書式の添え字ラベルと同様に、 explicit な indicator -> が含まれていなくても、 implicit (古典的なアインシュタイン縮約表記) の計算は実行されます。

operands : list of array_like These are the arrays for the operation. If provided, the calculation is done into this array.

演算子 : 配列のリストです。 演算の対象となる複数の配列です。 与えられればこれらの配列に対して演算が適用されます。

dtype : {data-type, None}, optional If provided, forces the calculation to use the data type specified. Note that you may have to also give a more liberal casting parameter to allow the conversions. Default is None.

与えられた場合、計算において指定されたデータ タイプを使うことを強制します。 変換を許すように自由にパラメータをキャストすることができるかもしれません。

order : {'C', 'F', 'A', 'K'}, optional Controls the memory layout of the output. 'C' means it should be C contiguous. 'F' means it should be Fortran contiguous, 'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise. 'K' means it should be as close to the layout as the inputs as is possible, including arbitrarily permuted axes. Default is 'K'.

出力のメモリーのレイアウトを制御します。 C は C contigious です。 FFortran contigious です。 A は すべての入力が F なら F、そうでなければ C です。 K は、任意の順序の軸も含めて、可能な限り入力の形式と同じにします。 デフォルトは K です。

casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional Controls what kind of data casting may occur. Setting this to 'unsafe' is not recommended, as it can adversely affect accumulations.

データキャスティングを許可するかを制御します。 これを unsafe に設定することは非推奨。

'no' means the data types should not be cast at all. 'equiv' means only byte-order changes are allowed. 'safe' means only casts which can preserve values are allowed. 'same_kind' means only safe casts or casts within a kind, like float64 to float32, are allowed. 'unsafe' means any data conversions may be done. Default is 'safe'.

no はデータタイプはキャストされないようにします。 equiv はバイトオーダーの変換だけ許します。 safe は値が保持されるだけキャストを許します。 same kindfloat64 から float32 のような安全なキャストだけ許します。 unsafe はどんなデータ変換も起こりうることを意味します。 デフォルトは safe です。

optimize : {False, True, 'greedy', 'optimal'}, optional Controls if intermediate optimization should occur. No optimization will occur if False and True will default to the 'greedy' algorithm. Also accepts an explicit contraction list from the np.einsum_path function. See np.einsum_path for more details. Defaults to False.

中間の最適化が行われるべきかを示します。 False では最適化せず、 True では既定では greedy アルゴリズムが使われます。 np.einsum_path で生成した明示的な contraction list も受け付けます。 デフォルトは False です。

本当?このあたりはいっぱい See Also に書いてある。